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 BSerial.begin(9600); // open the serial port at 9600 bps:
}
voidloop()
{
val = analogRead(0); // read the input pinSerial.println(val);
digitalWrite(2, (val>>2 & B00000001)); // -------X Decimal value 1digitalWrite(3, (val>>2 & B00000010)); // ------X- Decimal value 2digitalWrite(4, (val>>2 & B00000100)); // -----X-- Decimal value 4digitalWrite(5, (val>>2 & B00001000)); // ----X--- Decimal value 8digitalWrite(6, (val>>2 & B00010000)); // ---X---- Decimal value 16digitalWrite(7, (val>>2 & B00100000)); // --X----- Decimal value 32digitalWrite(8, (val>>2 & B01000000)); // -X------ Decimal value 64digitalWrite(9, (val>>2 & B10000000)); // X------- Decimal value 128delay(500);
}