Created
May 17, 2018 19:16
-
-
Save WTFox/58a2278acda17888020281485776f14f to your computer and use it in GitHub Desktop.
Music box controller
This file contains hidden or 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
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