-
-
Save YuruPuro/41d4154441f10c34aa7da95a7ab45891 to your computer and use it in GitHub Desktop.
M5Atom LITE/M5Stamp PICO ONBOARD COLOR 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
/** | |
* M5Atom LITE / M%Stamp PICO オンボードのカラーLED 色を変えるデモプログラム | |
**/ | |
#define RGBPIN 27 | |
#define BTNPIN 39 | |
#define LEDPIN 25 | |
int BTN = LOW ; | |
void sendBitData(uint32_t bitData) { | |
for (uint32_t sendBit = 0x00800000;sendBit!=0;sendBit>>=1) { | |
if ((bitData & sendBit) == 0 ) { | |
digitalWrite(RGBPIN,HIGH); | |
for (int L=0;L<2;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
digitalWrite(RGBPIN,LOW); | |
for (int L=0;L<5;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
} else { | |
digitalWrite(RGBPIN,HIGH); | |
for (int L=0;L<3;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
digitalWrite(RGBPIN,LOW); | |
for (int L=0;L<3;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
} | |
} | |
} | |
void setup() { | |
pinMode(RGBPIN,OUTPUT) ; | |
pinMode(BTNPIN,INPUT) ; | |
pinMode(LEDPIN,OUTPUT) ; | |
digitalWrite(LEDPIN,LOW); | |
digitalWrite(RGBPIN,LOW); | |
delayMicroseconds(80) ; | |
} | |
void loop() { | |
digitalWrite(LEDPIN,LOW); | |
sendBitData(0x00FF0000) ; | |
delay(500) ; | |
sendBitData(0x0000FF00) ; | |
delay(500) ; | |
sendBitData(0x000000FF) ; | |
delay(500) ; | |
for (int i=0;i<256;i+=16) { // G-B | |
uint32_t rgb = i << 16 | 0x000000FF ; | |
sendBitData(rgb) ; | |
delay(100) ; | |
} | |
for (int i=0;i<256;i+=16) { // GR- | |
uint32_t rgb = i << 8 | 0x00FF0000 ; | |
sendBitData(rgb) ; | |
delay(100) ; | |
} | |
for (int i=0;i<256;i+=16) { // -RB | |
uint32_t rgb = i | 0x0000FF00 ; | |
sendBitData(rgb) ; | |
delay(100) ; | |
} | |
} |
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
/** | |
* 空ループの経過時間を調整するためのテストプログラム | |
**/ | |
#define RGBPIN 27 | |
#define BTNPIN 39 | |
#define LEDPIN 25 | |
int BTN = LOW ; | |
void setup() { | |
Serial.begin(115200); | |
while (!Serial) { delay(1); } | |
pinMode(RGBPIN,OUTPUT) ; | |
pinMode(LEDPIN,OUTPUT) ; | |
pinMode(BTNPIN,INPUT) ; | |
digitalWrite(RGBPIN,LOW) ; | |
delayMicroseconds(80) ; | |
Serial.println("--- STRAT"); | |
digitalWrite(LEDPIN,HIGH) ; | |
unsigned long stratTime = micros( ) ; | |
// ----- | |
for (int N=0;N<1000;N++) { | |
digitalWrite(LEDPIN,HIGH) ; | |
for (int L=0;L<3;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
} | |
// ----- | |
unsigned long endTime = micros( ) - stratTime ; | |
Serial.print("--- BIT 1 :"); | |
Serial.println(endTime); | |
stratTime = micros( ) ; | |
// ----- | |
for (int N=0;N<1000;N++) { | |
digitalWrite(LEDPIN,HIGH) ; | |
for (int L=0;L<2;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
} | |
// ----- | |
endTime = micros( ) - stratTime ; | |
Serial.print("--- BIT 0 HIGH :"); | |
Serial.println(endTime); | |
stratTime = micros( ) ; | |
// ----- | |
for (int N=0;N<1000;N++) { | |
digitalWrite(LEDPIN,HIGH) ; | |
for (int L=0;L<5;L++) { | |
BTN = digitalRead(BTNPIN); | |
} | |
} | |
// ----- | |
endTime = micros( ) - stratTime ; | |
Serial.print("--- BIT 0 LOW :"); | |
Serial.println(endTime); | |
Serial.println("--- END"); | |
digitalWrite(LEDPIN,LOW) ; | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment