ROLLER/REVERSE-ROLLER
Description : With a potentiometer, controlling which of four leds is selected while a tact switch determines whether it is off or on (in contrast with the other leds).
The higher the value mesured of the potentiometer the further the led selected. When the switch is pressed, that led will light up, if not, all but the led selected will light up.
const char L1 = 2;
const char L2 = 3;
const char L3 = 4;
const char L4 = 5;
char sw = 7;
char swValue = 0;
long pot = A0;
long potvalue = 0;
int ON;
int OFF;
void setup() {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(sw, INPUT);
Serial.begin(9600);
}
void loop() {
swValue = digitalRead(sw);
potvalue = analogRead(pot);//*(5/1023)*50;
potvalue = map(potvalue,0,1023,0,255);
tact();
roller();
}
void tact(){
if (swValue==1)
{
ON =0;
OFF = 255;
}
else if (swValue==0)
{
ON=255;
OFF=0;
}
}
void roller () {
if (potvalue>=0 && potvalue<=63){
digitalWrite(L1, ON);
digitalWrite(L2, OFF);
digitalWrite(L3, OFF);
digitalWrite(L4, OFF);
}
else if (potvalue>=63 && potvalue<=63*2){
digitalWrite(L1, OFF);
digitalWrite(L2, ON);
digitalWrite(L3, OFF);
digitalWrite(L4, OFF);
}
else if (potvalue>=63*2 && potvalue<=63*3){
digitalWrite(L1, OFF);
digitalWrite(L2, OFF);
digitalWrite(L3, ON);
digitalWrite(L4, OFF);
}
else if (potvalue>=63*3 && potvalue<=63*4){
digitalWrite(L1, OFF);
digitalWrite(L2, OFF);
digitalWrite(L3, OFF);
digitalWrite(L4, ON);
}
}
Description : With a potentiometer, controlling which of four leds is selected while a tact switch determines whether it is off or on (in contrast with the other leds).
The higher the value mesured of the potentiometer the further the led selected. When the switch is pressed, that led will light up, if not, all but the led selected will light up.
CODE
const char L1 = 2;
const char L2 = 3;
const char L3 = 4;
const char L4 = 5;
char sw = 7;
char swValue = 0;
long pot = A0;
long potvalue = 0;
int ON;
int OFF;
void setup() {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(sw, INPUT);
Serial.begin(9600);
}
void loop() {
swValue = digitalRead(sw);
potvalue = analogRead(pot);//*(5/1023)*50;
potvalue = map(potvalue,0,1023,0,255);
tact();
roller();
}
void tact(){
if (swValue==1)
{
ON =0;
OFF = 255;
}
else if (swValue==0)
{
ON=255;
OFF=0;
}
}
void roller () {
if (potvalue>=0 && potvalue<=63){
digitalWrite(L1, ON);
digitalWrite(L2, OFF);
digitalWrite(L3, OFF);
digitalWrite(L4, OFF);
}
else if (potvalue>=63 && potvalue<=63*2){
digitalWrite(L1, OFF);
digitalWrite(L2, ON);
digitalWrite(L3, OFF);
digitalWrite(L4, OFF);
}
else if (potvalue>=63*2 && potvalue<=63*3){
digitalWrite(L1, OFF);
digitalWrite(L2, OFF);
digitalWrite(L3, ON);
digitalWrite(L4, OFF);
}
else if (potvalue>=63*3 && potvalue<=63*4){
digitalWrite(L1, OFF);
digitalWrite(L2, OFF);
digitalWrite(L3, OFF);
digitalWrite(L4, ON);
}
}
Comments
Post a Comment