Code syntax error

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

Code syntax error

Post by 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: 288
Joined: Sun May 04, 2014 8:54 am

Re: Code syntax error

Post by 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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Code syntax error

Post by 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: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Code syntax error

Post by deshipu » Wed Feb 01, 2017 12:00 am

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

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

Re: Code syntax error

Post by Turbinenreiter » Wed Feb 01, 2017 12:45 pm

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

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Code syntax error

Post by rhubarbdog » Wed Nov 15, 2017 2:11 am

It's hard to tell without indentation, i think your code reads

Code: Select all

if agx > 300:
steps+=1
But should read

Code: Select all

if agx > 300:
    steps+=1

Post Reply