Instructables

Electromagnet Superhero Glove

Step 10: Program Arduino.

Picture of Program Arduino.
Select the right COM port. My board is a Lilypad ATmega 328.

Here is the code:

const int finger = 8;
const int palm = 5;
const int button = 13;
const int empin = 10;
int buttonstate = 0;
int sensorstate = 0;

void setup() {
  pinMode(button, INPUT);
  pinMode(finger, OUTPUT);
  pinMode(palm, INPUT);
  pinMode(empin, OUTPUT);

}

void loop() {
  digitalWrite(palm, HIGH);
  buttonstate = digitalRead(button);
  sensorstate = digitalRead(finger);
  if (buttonstate == HIGH){
    if (sensorstate == LOW){
      digitalWrite(empin, HIGH);
    }
  }
  else{
    digitalWrite(empin, LOW);
  }

}
 
Remove these adsRemove these ads by Signing Up