Hi I have made a code to get random numbers between 0-256 and then output it as binary to LEDs and show the binary sequence. Both the random number and the binary sequence must be displayed to the monitor which is working fine. I am having a little trouble with the check test which somewhat has to resemble: Check-test: d02^7+d12^6+d22^5+d32^4+d42^3+d52^2+d62^1+d72^0 = random number.
Heres the code:
int ledPins[] = {2,3,4,5,6,7,8,9};
int d[] = {1,2,4,8,16,32,64,128};
long randNumber;
void setup()
{
Serial.begin(9600);
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 8; i++)
{
pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
}
randomSeed(analogRead(0));
for (int i=0; i<8; i++)
{
digitalWrite(ledPins[i], HIGH);
delay(500);
continue;
while(1){}
}
}
void loop()
{
for(int i=0; i<8; i++)
{
digitalWrite(ledPins[i], LOW);
delay(5);
continue;
while(1){}
}
randNumber = random(0,256);
Serial.print("\n");
Serial.println("Random Integer: ");
Serial.println(randNumber);
Serial.println("Binary Sequence: ");
for (int i=0; i<8; i++)
{
if (randNumber%2)
{
digitalWrite(ledPins[i], HIGH);
Serial.print("1");
}
else
{
digitalWrite(ledPins[i], LOW);
Serial.print("0");
}
randNumber/=2;
digitalRead(ledPins[i]);
if (ledPins[i]=HIGH)
{
}
else
{
}
delay(300);
}
delay(4000);
}