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)
Code syntax error
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Code syntax error
Code: Select all
val = val + 1
Code: Select all
val =+ 1
Last edited by Turbinenreiter on Wed Feb 01, 2017 12:44 pm, edited 1 time in total.
Re: Code syntax error
Just being nit picky here, but:
Code: Select all
>>> val = 7
>>> val += 1
>>> val
8
>>> val =+ 1
>>> val
1
Re: Code syntax error
Hard to say what is wrong with that code without seeing the indentation...
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Code syntax error
Listen to Dave not me. Don't know what I was thinking.
-
- Posts: 168
- Joined: Tue Nov 07, 2017 11:45 pm
Re: Code syntax error
It's hard to tell without indentation, i think your code reads
But should read
Code: Select all
if agx > 300:
steps+=1
Code: Select all
if agx > 300:
steps+=1