Created
October 12, 2016 18:34
-
-
Save hhayley/fe677f41132acae639e37a52471b329d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//electromagnet test 01 | |
int onBtn = 2; | |
int btnState = 0; | |
int mag = 9; | |
int led = 13; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize digital pin 13 as an output. | |
pinMode(mag, OUTPUT); | |
pinMode(led, OUTPUT); | |
pinMode(onBtn, INPUT); | |
Serial.begin(9600); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
btnState = digitalRead(onBtn); | |
Serial.println(btnState); | |
if (btnState == 1){ | |
digitalWrite(mag, HIGH); | |
digitalWrite(led, HIGH); | |
}else{ | |
digitalWrite(mag, LOW); // turn the LED off by making the voltage LOW | |
digitalWrite(led, LOW); | |
} | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment