Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino for Kids - Party Strobe Light
- *
- * learnelectronics
- * 31 JUL 2017
- *
- * www.youtube.com/c/learnelectronics
- */
- #define mosfet 5 //MOSFET gate on digital pin 5
- #define pot A0 //wiper from potentiometer on analog pin 0
- int wait = 0; //ultimate delay time
- void setup() {
- pinMode(5,OUTPUT); //digital pin 5 set for output
- pinMode(A0,INPUT); //analog pin 0 set for input
- Serial.begin(9600); //begin serial comms for debuging
- }
- void loop() {
- int pRead = analogRead(pot); //begin each loop by reading the position of the pot
- wait = map(pRead,0,1023,100,2000); //map the analog read to a value between 100mS to 2 seconds
- Serial.print(pRead); //send variables to serial monitor for debugging
- Serial.print("-->");
- Serial.println(wait); //send variables to serial monitor for debugging
- digitalWrite(mosfet,HIGH); //flash the MOSFET
- delay(100); //wait 100mS
- digitalWrite(mosfet,LOW); //shut off the MOSFET
- delay(wait); //wait for the time specified in the wait variable
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement