/**
Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/stdlib.h"
const uint ledPins[] = {13, 9, 6, 2};
const int led_count = sizeof(ledPins) / sizeof(int);
int main() {
const uint buttonPin = 27;
const uint TSLEEP = 500;
volatile uint8_t counter = 0;
//initialisierung button
gpio_init(buttonPin);
gpio_set_dir(buttonPin, GPIO_IN);
gpio_pull_up(buttonPin);
for (int i = 0; i < led_count; ++i) {
gpio_init(ledPins[i]);
gpio_set_dir(ledPins[i], GPIO_OUT);
}
while (true) {
while (gpio_get(buttonPin)==0) {
counter++;
sleep_ms(TSLEEP);
if (counter > 15) {
counter = 0;
}
for (int i = 0; i < led_count; ++i) {
gpio_put(ledPins[i], 0);
}
}
for (int i = 0; i < led_count; ++i) {
gpio_put(ledPins[i], (counter >> i) & 0x01);
}
}
}