I'm trying to alternatively have a random int generate a binary number with 4 lights.
This is my current code, However, it seems that all the lights(leds) go on, I don't think the minus option works. As in, it won't take a value from the currently randomized digit. (randombinary = randombinary - x)
I also tried just "randombinary - x"
const int button = 2;
const int redone = 13;
const int redtwo = 8;
const int greenone = 12;
const int greentwo = 7;
int randomnumber = 0;
int randombinary = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
delay(1000);
int randomnumber = (1, 15);
randombinary = randomnumber;
if (randombinary >=8){
digitalWrite(redone, HIGH);
randombinary = randombinary - 8;
}
else {
digitalWrite(redone, LOW);
}
if (randombinary >=4){
digitalWrite(greenone, HIGH);
randombinary = randombinary - 4;
}
else {
digitalWrite(greenone, LOW);
}
if (randombinary >=2){
digitalWrite(redtwo, HIGH);
randombinary = randombinary - 2;
}
else {
digitalWrite(greentwo, LOW);
}
if (randombinary >=1){
digitalWrite(greentwo, HIGH);
randombinary = randombinary - 1;
}
else {
digitalWrite(greentwo, LOW);
}
}
Would appreciate any help!