Last active
March 15, 2021 00:33
-
-
Save Tamakichi/122c7d3489fc1b337d27dd7a5fb67a6b to your computer and use it in GitHub Desktop.
Raspberry Pi Picoで8個のLEDの制御(padのDRIVEの検証用)
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
#include <stdio.h> | |
#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() { | |
// 標準入出力の初期化(USB CDC利用) | |
stdio_init_all(); | |
sleep_ms(5000); | |
// ピンの機能割り付け | |
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); | |
} | |
// GPIO2 padのdriveの値確認 | |
uint8_t pad_drive = (padsbank0_hw->io[2] & PADS_BANK0_GPIO0_DRIVE_BITS) >> PADS_BANK0_GPIO0_DRIVE_LSB; | |
printf("GPIO2 DRIVE:%0x\n",pad_drive); | |
// GPIO2 のDRIVEを12mAに変更 | |
hw_write_masked( | |
&padsbank0_hw->io[2], | |
PADS_BANK0_GPIO0_DRIVE_VALUE_12MA<<PADS_BANK0_GPIO0_DRIVE_LSB, | |
PADS_BANK0_GPIO0_DRIVE_BITS | |
); | |
// GPIO2 padのdriveの値確認 | |
pad_drive = (padsbank0_hw->io[2] & PADS_BANK0_GPIO0_DRIVE_BITS) >> PADS_BANK0_GPIO0_DRIVE_LSB; | |
printf("GPIO2 DRIVE:%0x\n",pad_drive); | |
// 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