Cannot get my if statements to work #11171
Replies: 5 comments 7 replies
-
You really should edit your message to fix up the formatting. It is impossible to be sure just what you are trying to do. (See the github markdown docs) I have pasted below what it seems you meant. In that case, there is only one uncommented import machine
from machine import Pin
import time
# define pins
RX = machine.Pin(1, machine.Pin.IN, Pin.PULL_DOWN)
CTR = machine.Pin(9, machine.Pin.IN, Pin.PULL_UP)
STAT = machine.Pin(10, machine.Pin.IN, Pin.PULL_UP)
TX = machine.Pin(0, machine.Pin.OUT)
# SDA = machine.Pin(2, machine.Pin.OUT)
# SCK = machine.Pin(3, machine.Pin.OUT)
A0 = machine.Pin(4, machine.Pin.OUT)
A1 = machine.Pin(5, machine.Pin.OUT)
A2 = machine.Pin(6, machine.Pin.OUT)
CS = machine.Pin(7, machine.Pin.OUT)
RH = machine.Pin(8, machine.Pin.OUT)
RESET = machine.Pin(11, machine.Pin.OUT)
HALT = machine.Pin(12, machine.Pin.OUT)
START = machine.Pin(13, machine.Pin.OUT)
LED = machine.Pin(25, machine.Pin.OUT)
# end define pins
while True:
# Create I2C object
i2c = machine.I2C(1, scl=machine.Pin(3), sda=machine.Pin(2))
# Print out any addresses found
devices = i2c.scan()
if devices:
for d in devices:
print(hex(d))
time.sleep(2)
# if STAT.value != ():
LED(1)
RX(1)
# SDA(1)
# SCK(1)
A0(1)
A1(1)
A2(1)
CS(1)
RH(1)
# CTR(1)
# STAT(1)
RESET(1)
HALT(1)
START(1)
print("Stat Change")
time.sleep(2)
# if CTR.value != ():
LED(0)
RX(0)
# SDA(0)
# SCK(0)
A0(0)
A1(0)
A2(0)
CS(0)
RH(0)
# CTR(0)
# STAT(0)
RESET(0)
HALT(0)
START(0)
print("Ctr Change")
time.sleep(3) |
Beta Was this translation helpful? Give feedback.
-
Add lines with three backticks ``` before and after your code |
Beta Was this translation helpful? Give feedback.
-
I have edited my code per Robert's direction and am still awaiting a reply. |
Beta Was this translation helpful? Give feedback.
-
If I were you, I would try simple things first in the interactive shell. By simple things I mean starting from one input pin that triggers one output pin inside of your while loop. Because you have a sleep(1) if your pin trigger happens while in the sleep(1) and trigger signal is shorter than 1 second it will miss it. In anyway, it is best to use interrupts but at this stage I highly recommend to just try things out in the interactive mode (REPL): Once you have your pin -> led activation with your while loop (make it having sleep(0.1)), you should move on to interrupts ASAP: Remember: indentation is crucial, and you should stick to 4 spaces (configure your editor/ide to convert the TABs to 4 spaces if you insist on "TAB"-ing). |
Beta Was this translation helpful? Give feedback.
-
I want to thank all of you for your help. I am probably making a very basic mistake. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
I am very new to Python.
I cannot seem to get my if statements to work.
Beta Was this translation helpful? Give feedback.
All reactions