/**
Raspberry Pi Pico LED Bar Graph Binary Counter
https://wokwi.com/arduino/projects/309828467927548481
Copyright (C) 2021 Uri Shaked
*/
const int pins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
const int joystickPin = 26;
void setup() {
for (int i = 0; i < 10; i++) {
pinMode(pins[i], OUTPUT);
}
}
void loop() {
int joystickValue = analogRead(joystickPin);
int displayValue = map(joystickValue, 0, 1023, 0, 9);
displayBar(displayValue);
delay(50);
}
void displayBar(int value) {
for (int i = 0; i < 10; i++) {
digitalWrite(pins[i], i <= value ? HIGH : LOW);
}
}