Skip to content

Instantly share code, notes, and snippets.

@WTFox
Created May 17, 2018 19:16
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 WTFox/58a2278acda17888020281485776f14f to your computer and use it in GitHub Desktop.
Save WTFox/58a2278acda17888020281485776f14f to your computer and use it in GitHub Desktop.
Music box controller
int REED_PIN = D0;
int MOTOR_PIN = D3;
int LED_PIN = D7;
int MOTOR_SPEED = 255;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(REED_PIN, INPUT_PULLUP);
pinMode(MOTOR_PIN, OUTPUT);
}
void loop() {
bool lidIsOpen = digitalRead(REED_PIN) == LOW;
if (lidIsOpen) {
digitalWrite(LED_PIN, HIGH);
startMotor();
} else {
digitalWrite(LED_PIN, LOW);
stopMotor();
}
}
void startMotor() {
analogWrite(MOTOR_PIN, MOTOR_SPEED);
}
void stopMotor() {
analogWrite(MOTOR_PIN, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment