Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:779a9ff709b7
- Child:
- 1:dc680896cbaa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Oct 13 14:21:42 2020 +0000
@@ -0,0 +1,158 @@
+#include "mbed.h"
+#include "hanabi.h"
+
+#define BAR0 0b00000001
+#define BAR1 0b00000010
+#define BAR2 0b00000100
+#define BAR3 0b00001000
+#define BAR4 0b00010000
+#define BAR5 0b00000001
+#define BAR6 0b00000010
+#define BAR7 0b00000100
+#define BAR8 0b00001000
+#define BAR9 0b00010000
+
+#define TIME 25 //us
+
+
+DigitalOut red(D12);
+DigitalOut blue(D11);
+DigitalOut green(D10);
+
+DigitalOut bar0(A0);
+DigitalOut bar1(A1);
+DigitalOut bar2(A2);
+DigitalOut bar3(PA_8);
+DigitalOut bar4(PF_1);
+DigitalOut bar5(PF_0);
+DigitalOut bar6(PB_1);
+DigitalOut bar7(PB_0);
+DigitalOut bar8(PA_12);
+DigitalOut bar9(PA_10);
+
+DigitalIn sw0(D13);
+DigitalIn sw1(A6);
+
+Serial pc(USBTX, USBRX);
+Ticker timer;
+
+char RGB(int, char, char);
+void TMR0_ISR();
+
+int main(){
+ bool tim_flag = 0;
+ char tim = 25;
+ timer.attach_us(&TMR0_ISR, tim);
+ pc.baud(115200);
+ while(1){
+ if(sw0){
+ tim --;
+ tim_flag = 1;
+ }else if(sw1){
+ tim ++;
+ tim_flag = 1;
+ }
+
+ if(tim_flag){
+ pc.printf("period: %d, freq: %f\n", tim, float(1/tim)
+ );
+ timer.detach();
+ timer.attach_us(&TMR0_ISR, tim);
+ tim_flag = 0;
+ }
+ }
+}
+
+char RGB(int row, char col, char bar){
+ char color;
+ char judge_red = 0, judge_green = 0, judge_blue = 0;
+
+ judge_red = red0[row][col] & bar;
+ judge_green = green0[row][col & bar];
+ judge_blue = blue0[row][col] & bar;
+
+ bool flag = 1;
+
+ if(judge_red && judge_green && judge_blue){
+ red=0;
+ green=0;
+ blue=0;
+ }else if(judge_red && judge_green){
+ red=0;
+ green=0;
+ blue=1;
+ }else if(judge_red && judge_blue){
+ red=0;
+ green=1;
+ blue=0;
+ }else if(judge_blue && judge_green){
+ red=1;
+ green=0;
+ blue=0;
+ }else if(judge_red){
+ red=0;
+ green=1;
+ blue=1;
+ }else if(judge_green){
+ red=1;
+ green=0;
+ blue=1;
+ }else if(judge_blue){
+ red=1;
+ green=1;
+ blue=0;
+ }else{
+ red=1;
+ green=1;
+ blue=1;
+ flag = 0;
+ }
+ return flag;
+}
+
+void TMR0_ISR(void)
+{
+ static char i = 0;
+ static short j = 0;
+ switch(i){
+ case 0:
+ bar0 = RGB(j, 0, BAR0);
+ break;
+ case 1:
+ bar1 = RGB(j, 0, BAR1);
+ break;
+ case 2:
+ bar2 = RGB(j, 0, BAR2);
+ break;
+ case 3:
+ bar3 = RGB(j, 0, BAR3);
+ break;
+ case 4:
+ bar4 = RGB(j, 0, BAR4);
+ break;
+ case 5:
+ bar5 = RGB(j, 1, BAR5);
+ break;
+ case 6:
+ bar6 = RGB(j, 1, BAR6);
+ break;
+ case 7:
+ bar7 = RGB(j, 1, BAR7);
+ break;
+ case 8:
+ bar8 = RGB(j, 1, BAR8);
+ break;
+ case 9:
+ bar9 = RGB(j, 1, BAR9);
+ break;
+ }
+
+ i++;
+ j++;
+ if(i > 9)
+ i = 0;
+ if(j > 180)
+ j = 0;
+
+}
+