General

Getting a code error of indention. Using upycraft.

userHead AnneGodkona 2022-11-30 20:25:54 238 Views1 Replies

Here is the code:

import machine import time trig = machine.Pin(2, machine.Pin.OUT) echo = machine.Pin(0, machine.Pin.IN) green = machine.Pin(12, machine.Pin.OUT)   def get_distance(): trig.value(0) time.sleep(0.0001) trig.value(1)    while echo == 1: start = time.time()  while echo == 0: end = time.time() sig_time = end-start   distance = sig_time / 0.000148   print( 'Distance: {} cm' .format(distance)) return distance while True:   get_distance()

The error is: Traceback (Most recent call last):

File stdin line 1 in module

File <string>, line 14

Indentation error: unindent does not match any outer indentation level

I am lost. It looks like my indents are correct. Please help.

2023-02-23 11:48:05

Hi

Normally, this error is caused by incorrect Indentation formats. Could you please all use TAB or all use spaces to adjust your indentation?

Hope it can help.

userHeadPic NeloKin