Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int led_pins[] = {11, 13, 2, 3, 4, 5, 6, 7};
- const int pin_count = sizeof(led_pins) / sizeof (led_pins[0]);
- int joy_pin = A0;
- void setup() {
- for (int i = 0; i < pin_count; i++) {
- pinMode(led_pins[i], OUTPUT);
- }
- Serial.begin(9600);
- }
- void loop() {
- int joystick_input = analogRead(joy_pin);
- int converted_joy_input = joystick_input / (1000 / (pin_count - 1));
- int led_to_light = led_pins[converted_joy_input];
- Serial.println(converted_joy_input);
- for (int i = 0; i < pin_count; i++) {
- if(i != converted_joy_input) {
- digitalWrite(led_pins[i], LOW);
- }
- }
- digitalWrite(led_to_light, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement