78Views15Replies

# a led and a pot that controlls an 8 leds whrein the last state of the pot will be the starting point of the push buton? Answered

Tags:

## 15 Replies

AmenolaS (author)2017-12-08

steveastrouk (author)2017-12-08

steveastrouk (author)2017-12-07

RIGHT. With a decent description we can help !

Here's something which you'll need to modify a bit to get exactly what you want, its not in Arduino code, but you should get a rough idea.

loop()

{

Meas=map(ANIN,0,1024,0,7);

if (Pushctr>MEAS)

{Meas=Meas+pushctr};

//turn all leds off at start of testing loop with some little subroutine - call it alloff;

alloff;

if (meas=0) led1=TRUE;

if (meas=1) led2=TRUE;

if (meas=2) led3=TRUE;

if (meas=3) led4=TRUE;

if (meas=4) led5=TRUE;

if (meas=5) led6=TRUE;

if (meas=6) led7=TRUE;

if (meas=7) led8=TRUE;

if (pushbutton =TRUE)

{pushcounter++;

if (pushcounter>8) pushcounter=0;

WHILE (pushbutton=TRUE) {}

}

steveastrouk (author)2017-12-06

You aren't making sense at all, so we can't help

AmenolaS (author)2017-12-06

sorry, its just it kills me. I have the code for both of them but when i try to combine them, it doesnt work as i want it to be.

AmenolaS (author)2017-12-06

heres the code and i dont know what to put in the loop part.

const int buttonPin = 2;

const int analogPin = A0;

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;

int buttonState = 0; // variable for reading the pushbutton status

int buttonPressCount = 0;

int numberOfLED = 5;

int analogValue=0;

void setup() {

// put your setup code here, to run once:

pinMode (ledPin1, OUTPUT);

pinMode (ledPin2, OUTPUT);

pinMode (ledPin3, OUTPUT);

pinMode (ledPin4, OUTPUT);

pc);

pinMode(analogPin, INPUT);

pinMode(buttonPin, INPUT);

Serial.begin(9600);

}

void loop() {

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

}

void potFunction(){

if(analogValue <128){

digitalWrite(ledPin1,HIGH);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue >128 && analogValue <256){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,HIGH);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue >256 && analogValue <384){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,HIGH);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue >384 && analogValue <512){

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,HIGH);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue <512 && analogValue >640) {

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,HIGH);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue > 640 && analogValue <768) {

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,HIGH);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,LOW);}

else if(analogValue >768 && analogValue <896) {

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,HIGH);

digitalWrite(ledPin8,LOW);}

else{

digitalWrite(ledPin1,LOW);

digitalWrite(ledPin2,LOW);

digitalWrite(ledPin3,LOW);

digitalWrite(ledPin4,LOW);

digitalWrite(ledPin5,LOW);

digitalWrite(ledPin6,LOW);

digitalWrite(ledPin7,LOW);

digitalWrite(ledPin8,HIGH); }

Serial.println(analogValue);

delay(1);

}

void buttonFunction(){

if (buttonState == HIGH) {

if (buttonPressCount % numberOfLED == 0) {

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) {

digitalWrite(ledPin3, HIGH);

} else {

digitalWrite(ledPin3, LOW);

}

if (buttonPressCount % numberOfLED == 3) {

digitalWrite(ledPin4, HIGH);

} else {

digitalWrite(ledPin4, LOW);

}

if (buttonPressCount % numberOfLED == 4) {

digitalWrite(ledPin5, HIGH);

}

else {

digitalWrite(ledPin5, LOW);

}

if (buttonPressCount % numberOfLED == 5) {

digitalWrite(ledPin6, HIGH);

} else {

digitalWrite(ledPin6, LOW);

}

if (buttonPressCount % numberOfLED == 6) {

digitalWrite(ledPin7, HIGH);

} else {

digitalWrite(ledPin7, LOW);

}

if (buttonPressCount % numberOfLED == 7) {

digitalWrite(ledPin8, HIGH);

} else {

digitalWrite(ledPin8, LOW);

}

buttonPressCount++;

delay(400);

}

}

iceng (author)2017-12-05

Could you be calling the microprocessor == uP a "pot" ?

Because a pot is short for potentiometer which is a manually variable resistor..

And if it is a pot what does it used for

A] dimming the LED light ?

B] changing the speed ?

C] or tell us what...

AmenolaS (author)2017-12-06

no a potentioimeter and a push button that

iceng (author)2017-12-06

BUT What Do YOU Want to Happen When YOU Turn the POT ????

AmenolaS (author)2017-12-06

when i turn the pot at a specific range such as analogValue<128 ,the first led lit and as i increases the range the next led lit and so on. the push button here acts as another input such as, as a push it the last state of the pot will be its starting point and as a push it again it lit the next led and so on. it goes by as i change the pot or the push button. tahnks

AmenolaS (author)2017-12-06

A potentiometr and a push button that controlls an 8 leds. pot here acts as a controller for the lighting of the led such as when at spicific range , one of the leds light and as the range increases it goes to the next led. As for the push button, the last state for the pot will be its starting point and it goes as i push the button to the next led. thank you

AmenolaS (author)2017-12-06

A potentiometr and a push button that controlls an 8 leds. pot here acts as a controller for the lighting of the led such as when at spicific range , one of the leds light and as the range increases it goes to the next led. As for the push button, the last state for the pot will be its staring point and it goes as i push the button to the next led. thank you

rickharris (author)2017-12-05

Broken

iceng (author)2017-12-05

I know a good refurbish and polish service for damaged globes that are injured by some crazy thinking members asking impossible to mind read questions over and over ;-)

steveastrouk (author)2017-12-05

?