Code syntax error

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Backintime
Posts: 1
Joined: Tue Jan 31, 2017 8:02 pm

Code syntax error

Postby Backintime » Tue Jan 31, 2017 8:08 pm

Hello everyone,

I'm working on a pedometer feature for my micro:bit and I'm trying to upload the following code below. However, after it's uplodaed, this error message appears:
line 7 syntax error - invalid syntax

I can't find the correct syntax that would make the code work. Could somebody help me on this one? ;) Thanks!

from microbit import *
steps = 0
while True:
#display.clear()
agx = accelerometer.get_x()
if agx > 300:
steps += 1
sleep(100)
if steps > 0:
display.set_pixel(0,0,9)
if steps > 10:
display.set_pixel(1,0,9)
if steps > 20:
display.set_pixel(2,0,9)
if steps > 30:
display.set_pixel(3,0,9)
if steps > 40:
display.set_pixel(4,0,9)
if steps > 50:
display.set_pixel(0,1,9)
if steps > 60:
display.set_pixel(1,1,9)
if steps > 70:
display.set_pixel(2,1,9)
if steps > 80:
display.set_pixel(3,1,9)
if steps > 90:
display.set_pixel(4,1,9)

Turbinenreiter
Posts: 255
Joined: Sun May 04, 2014 8:54 am

Re: Code syntax error

Postby Turbinenreiter » Tue Jan 31, 2017 10:53 pm

Code: Select all

val = val + 1

short

Code: Select all

val =+ 1


//edit: this is bullshit, ignore it.
Last edited by Turbinenreiter on Wed Feb 01, 2017 12:44 pm, edited 1 time in total.

Online
User avatar
dhylands
Posts: 2260
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Code syntax error

Postby dhylands » Tue Jan 31, 2017 11:29 pm

Just being nit picky here, but:

Code: Select all

>>> val = 7
>>> val += 1
>>> val
8
>>> val =+ 1
>>> val
1

User avatar
deshipu
Posts: 931
Joined: Thu May 28, 2015 5:54 pm

Re: Code syntax error

Postby deshipu » Wed Feb 01, 2017 12:00 am

Hard to say what is wrong with that code without seeing the indentation...

Turbinenreiter
Posts: 255
Joined: Sun May 04, 2014 8:54 am

Re: Code syntax error

Postby Turbinenreiter » Wed Feb 01, 2017 12:45 pm

Listen to Dave not me. Don't know what I was thinking.


Return to “The micro:bit”

Who is online

Users browsing this forum: No registered users and 1 guest