Currently using this code as a means to power on solenoids to hit various materials. One is a potentiometer and other two are 'manually' controlled.
I want to add 2 LEDs so that every time the buttons are pressed, they also light up. finding this harder than i suppose it should be? Moreover, is it possible to turn the potentiometer to a point where it turns off? Right now when turned all the way up it holds the solenoids which makes a loud noise if its 'on'
//potentiometer
int potentiometer = A0;
int potRead = 0;
int redLED = 7;
int isOn = 1;
long now = 0;
//button
byte led2 = 8;
byte button2 = 5;
//button2
byte led3 = 9;
byte button3 = 6;
void setup() {
// set the digital pin as output:
//potentiometer
pinMode(redLED,OUTPUT);
pinMode(potentiometer,INPUT);
digitalWrite(redLED,HIGH);
// button
pinMode (led2, OUTPUT); // pin to LED anode, LED cathode to resistor, resistor to Gnd
pinMode (button2, INPUT_PULLUP); // button connects pin to Gnd when pressed
//button 2
pinMode (led3, OUTPUT); // pin to LED anode, LED cathode to resistor, resistor to Gnd
pinMode (button3, INPUT_PULLUP); // button connects pin to Gnd when pressed
} // end setup
void loop()
{
// potentiometer.
potRead = analogRead(potentiometer);
if(millis() > now + potRead){
digitalWrite(redLED,isOn);
isOn = 1 - isOn;
now = millis();
}
//button1
if (digitalRead(button2) == LOW) {
digitalWrite (led2, HIGH);
}
else {
digitalWrite (led2, LOW);
}
//button2
//button1
if (digitalRead(button3) == LOW) {
digitalWrite (led3, HIGH);
}
else {
digitalWrite (led3, LOW);
}
} // end loop