Created
March 11, 2021 02:03
-
-
Save Tamakichi/41cdd6b92080f763ecf12fefa10381d5 to your computer and use it in GitHub Desktop.
Raspberry Pi Picoで8個のLEDの制御
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 8個のLEDの制御 | |
* 2021/03/03 たま吉さん | |
* | |
*/ | |
#include "pico/stdlib.h" | |
#define MAXLED 8 | |
// 8個のLEDのPIN番号割り付け | |
const uint8_t LED_PIN[MAXLED] = {2, 3, 4, 5, 6, 7, 8, 9}; | |
// 8個のLEDの更新表示 | |
void update(uint8_t value) { | |
for (uint8_t i=0; i < MAXLED; i++) { | |
gpio_put(LED_PIN[i], value & 0x80>>i ? 1:0); | |
} | |
} | |
// メイン | |
int main() { | |
// ピンの機能割り付け | |
for (uint8_t i = 0; i< MAXLED; i++) { | |
gpio_init(LED_PIN[i]); | |
gpio_set_dir(LED_PIN[i], GPIO_OUT); | |
gpio_put(LED_PIN[i], 0); | |
} | |
// LEDの表示更新ループ | |
while (true) { | |
update((uint8_t)0b10101010); | |
sleep_ms(250); | |
update((uint8_t)0b01010101); | |
sleep_ms(250); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment