Serial_LED(f303k8)
Dependencies: mbed PololuLedStrip
main.cpp
00001 #include "mbed.h" 00002 #include "PololuLedStrip.h" 00003 00004 PololuLedStrip ledStrip1(PB_1); 00005 PololuLedStrip ledStrip2(PB_0); 00006 PololuLedStrip ledStrip3(PA_11); 00007 PololuLedStrip ledStrip4(PA_7); 00008 00009 #define LED_COUNT 37 //LEDの数 00010 rgb_color colors[LED_COUNT]; 00011 rgb_color colors2[LED_COUNT]; 00012 rgb_color colors3[LED_COUNT]; 00013 rgb_color colors4[LED_COUNT]; 00014 00015 Serial Xbee(PA_9,PA_10,19200); //TX,RX,クロックレート 00016 Serial pc(SERIAL_TX,SERIAL_RX); //pc(USBTX,USBRX) 00017 unsigned char RX_data; 00018 00019 DigitalOut LED(PA_3); 00020 AnalogIn FT(PA_4); 00021 00022 Ticker flipper; //タイマー 00023 00024 //RS-555 rpm == 3610 00025 //rad/s == 378.0383159819718 00026 //ギア比は1:2だから上の2倍のはず 00027 00028 //フォトリフレクタ 00029 double fot; 00030 int h = 0; 00031 int b = 0; 00032 //↓LED色 00033 int R = 1; 00034 int G = 2; 00035 int B = 3; 00036 int Y = 4; 00037 int L = 5; 00038 int P = 6; 00039 int W = 7; 00040 int O = 8; 00041 00042 int LED_CON = 1; 00043 int con = 0; 00044 int FT_con = 0; 00045 00046 void Xbee_RX(){ 00047 RX_data = Xbee.getc(); //Xbeeから送られてきた文字Zに代入 00048 pc.putc(RX_data); //値をpcに表示 00049 } 00050 00051 rgb_color COLOR(float H,int n){ 00052 00053 float r = 0, g = 0, b = 0; 00054 H = 100; //光の強さ 00055 switch (n){ 00056 case 1:r = H; g = 0; b = 0; break; //赤 00057 case 2:r = 0; g = H; b = 0; break; //緑 00058 case 3:r = 0; g = 0; b = H; break; //青 00059 case 4:r = H; g = H; b = 0; break; //黄色 00060 case 5:r = 0; g = H; b = H; break; //水色 00061 case 6:r = H; g = 0; b = H; break; //紫 00062 case 7:r = H; g = H; b = H; break; //白 00063 case 8:r = H; g = H * 0.5; b = 0; break; //オレンジ 00064 } 00065 return (rgb_color){r,g,b}; 00066 } 00067 00068 //タイマー処理 00069 void LED_not(){ 00070 for(h = 0; h < LED_COUNT; h++){ 00071 uint8_t phase =(h << 1); 00072 colors[h] = COLOR(phase, 0); 00073 ledStrip1.write(colors, LED_COUNT); 00074 } 00075 } 00076 00077 00078 00079 00080 int main(){ 00081 Xbee.attach(&Xbee_RX, Serial::RxIrq); //割り込み 00082 pc.baud(115200); //pcクロックレート 00083 00084 while(1){ 00085 // if(RX_data == 'A'){ 00086 00087 if(FT < 0.8){ 00088 FT_con++; 00089 //Xbee.printf("%f",FT); 00090 while(FT < 0.8){ 00091 //Xbee.printf("%f",FT); 00092 } 00093 } 00094 // if(RX_data == 'A' && con == 0){ 00095 // con = 1; 00096 // } 00097 if(con == 0){ 00098 if(10 <= FT_con && FT_con < 20){ 00099 for(h = 0; h < LED_COUNT; h++){ 00100 uint8_t phase =(h << 1); 00101 colors[1] = COLOR(phase, B); 00102 ledStrip1.write(colors, LED_COUNT); 00103 00104 } 00105 LED_not(); 00106 } 00107 } 00108 00109 00110 00111 } 00112 }
Generated on Wed Jul 13 2022 10:30:06 by 1.7.2