can you help me on making a pot and a push button to control multiple leds?


sort by: active | newest | oldest
rickharris13 days ago

How do you want to control them.

Exactly what rype of LED.

AmenolaS (author)  rickharris12 days ago

such that the pot controls the multiple leds(8 leds) at minimum, it controls the first led and at maximum the last leds and at mid range the middle led and the button use as a cotroller as well such that the last state of the pot is the starting point of the push button. when i press the button, it goes next to the another leds.

AmenolaS (author)  AmenolaS12 days ago

heres my code and im trying to combine them both and it really annoys me a lot. hope you can help me and thanks

const int potPin=2;

const int val=0;

const int ledPin1 = 3;

const int ledPin2 = 4;

const int ledPin3 = 5;

const int ledPin4 = 6;

const int ledPin5 = 7;

const int ledPin6=8;

const int ledPin7=9;

const int ledPin8=10;

const int threshold= 512;

const int buttonPin=1;

int buttonState=0;

int buttonPressCount=0;

int numberOfLED=8;

void setup() {

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

pinMode(ledPin4, OUTPUT);

pinMode(ledPin5, OUTPUT);

pinMode(ledPin6, OUTPUT);

pinMode(ledPin7, OUTPUT);

pinMode(ledPin8, OUTPUT);

pinMode(buttonPin,INPUT);

Serial.begin(9600);

}

void loop() {

// put your main code here, to run repeatedly:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

if (buttonPressCount % numberOfLED == 0) {

// turn LED1 on:

digitalWrite(ledPin1, HIGH);

} else {

digitalWrite(ledPin1, LOW);

}

if (buttonPressCount % numberOfLED == 1) {

// turn LED1 on:

digitalWrite(ledPin2, HIGH);

} else {

digitalWrite(ledPin2, LOW);

}

if (buttonPressCount % numberOfLED == 2) {

// turn LED1 on:

digitalWrite(ledPin3, HIGH);

} else {

digitalWrite(ledPin3, LOW);

}

if (buttonPressCount % numberOfLED == 3) {

// turn LED1 on:

digitalWrite(ledPin4, HIGH);

} else {

digitalWrite(ledPin4, LOW);

}

if (buttonPressCount % numberOfLED == 4) {

// turn LED1 on:

digitalWrite(ledPin5, HIGH);

}

else {

digitalWrite(ledPin5, LOW);

}

if (buttonPressCount % numberOfLED == 5) {

// turn LED1 on:

digitalWrite(ledPin6, HIGH);

}

else {

digitalWrite(ledPin6, LOW);

}

if (buttonPressCount % numberOfLED == 6) {

// turn LED1 on:

digitalWrite(ledPin7, HIGH);

}

else {

digitalWrite(ledPin7, LOW);

}

if (buttonPressCount % numberOfLED == 7) {

// turn LED1 on:

digitalWrite(ledPin8, HIGH);

}

else {

digitalWrite(ledPin8, LOW);

}

buttonPressCount++;

delay(400);

}

int analogValue = analogRead(analogPin);

if(analogValue > 819){

digitalWrite(ledPin1,HIGH);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);}

else if(analogValue < 819 && analogValue > 615){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,HIGH);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);}

else if(analogValue < 615 && analogValue > 411){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,HIGH);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);}

else if(analogValue < 411 && analogValue > 241){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,HIGH);

digitalWrite(ledPin5,LOW);}

else {

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,HIGH);}

Serial.println(analogValue);

delay(1);

Serial.println(analogRead(potPin));

delay(1);

}

iceng13 days ago
(removed by author or community request)
AmenolaS (author)  iceng12 days ago

pls help me, such that i have 8 leds that could be controlled by a pot and a push button. the last state of the pot will be the starting point of my push button. thank you very much