int val = 0; // variable to store the value readvoidsetup()
{
DDRD = DDRD | B11111100; //Data Direction Register for Port D
DDRB = DDRB | B00000011; //Data Direction Register for Port B
}
voidloop()
{
val = analogRead(0); // read the input pindigitalWrite(2, (val & B00000001)); // -------X Decimal value 1digitalWrite(3, (val & B00000010)); // ------X- Decimal value 2digitalWrite(4, (val & B00000100)); // -----X-- Decimal value 4digitalWrite(5, (val & B00001000)); // ----X--- Decimal value 8digitalWrite(6, (val & B00010000)); // ---X---- Decimal value 16digitalWrite(7, (val & B00100000)); // --X----- Decimal value 32digitalWrite(8, (val & B01000000)); // -X------ Decimal value 64digitalWrite(9, (val & B10000000)); // X------- Decimal value 128delay(20);
}
}