Skip to content

Instantly share code, notes, and snippets.

@hhayley
Created October 12, 2016 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhayley/fe677f41132acae639e37a52471b329d to your computer and use it in GitHub Desktop.
Save hhayley/fe677f41132acae639e37a52471b329d to your computer and use it in GitHub Desktop.
//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