cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
741
Views
0
Helpful
0
Replies

Modify "Blink" for Rocker Switch to Control LED

ls22
Level 1
Level 1

Hello!

I am trying to modify the default main.py SBC0 code to use a WHILE loop in order for:

  1. The rocker switch controls the blinking LED: switch on = LED blinks; switch off = LED does not blink
    1. Starts off not blinking
  2. When I turn on the switch, the LED should be on for 2 secs and off for 2 secs (blink "cycle")
  3. Make a variable counting the number of times the LED blink
    1. Print the number of blinks once the switch is turned off.

Finally, I want to use FOR loop to blink the LED 9 times even when the switch is off.

 

Thank you in advance! Here is what I have:

from gpio import *
from time import *

def main():
	pinMode(2, IN)
	pinMode(1, OUT)
	while True:
		if digitalRead(2) == HIGH:
			digitalWrite(1, HIGH)
			print("Blinking")
		else:
			digitalWrite(1, LOW);
	delay(2000)
		#delay(500)

if __name__ == "__main__":
	main()

 

0 Replies 0
Review Cisco Networking for a $25 gift card