Created
September 12, 2019 10:12
-
-
Save JulianAGCarrera/0e408e2eabf51675e5b9d6d7d2b97282 to your computer and use it in GitHub Desktop.
Analog/Digital LEDs
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
const int knob = A0; //Potentiometer/knob pin | |
const int knobRed = 3; //Knob's red LED pin | |
const int knobGreen = 5; //Knob's green LED pin | |
const int button = A1; //Button's pin | |
const int buttonRed = 2; //Button's red LED pin | |
const int buttonGreen = 4; //Button's green LED pin | |
void setup() { | |
pinMode (knob, INPUT); | |
pinMode (knobRed, OUTPUT); | |
pinMode (knobGreen, OUTPUT); | |
pinMode (button, INPUT); | |
pinMode (buttonRed, OUTPUT); | |
pinMode (buttonGreen, OUTPUT); | |
} | |
void loop() { | |
int knobState; | |
bool knobRedOn = false; //to verify for the switch | |
bool knobGreenOn = false; | |
knobState = analogRead (knob); | |
if (knobState > 50 && knobState < 512) { | |
analogWrite (knobRed, knobState / 2); | |
knobRedOn = true; | |
} else { | |
analogWrite (knobRed, 0); | |
} | |
if (knobState > 512) { | |
analogWrite (knobGreen, knobState / 2); | |
knobGreenOn = true; | |
} else { | |
analogWrite (knobGreen, 0); | |
} | |
int buttonState; | |
buttonState = digitalRead (button); | |
if (knobRedOn) { | |
digitalWrite (buttonRed, buttonState); | |
} | |
if (knobGreenOn) { | |
digitalWrite (buttonGreen, buttonState); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment