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.
main.cpp
00001 #include "mbed.h" 00002 #include "SakuraIO.h" 00003 00004 DigitalOut status_led(PB_5); 00005 00006 DigitalOut patlite_r(PB_4); 00007 DigitalOut patlite_y(PB_3); 00008 DigitalOut patlite_g(PA_15); 00009 DigitalOut patlite_4(PA_12); 00010 DigitalOut patlite_5(PA_11); 00011 DigitalOut patlite_6(PA_8); 00012 DigitalOut patlite_7(PB_1); 00013 DigitalOut patlite_8(PB_0); 00014 00015 DigitalOut patlite_map[8] = { 00016 patlite_r, patlite_y, patlite_g, patlite_4, 00017 patlite_5, patlite_6, patlite_7, patlite_8 00018 }; 00019 00020 //SPI spi(D11, D12, D13); // mosi, miso, sclk 00021 //DigitalOut cs(D10); 00022 I2C i2c(PB_7, PB_6); // sda, scl 00023 uint64_t counter = 0; 00024 00025 00026 int main() 00027 { 00028 //SakuraIO_SPI sakuraio( spi, cs ); 00029 SakuraIO_I2C sakuraio(i2c); 00030 00031 // Waiting to come online 00032 for(;;) { 00033 if( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) break; 00034 for (int i = 0; i < 6; i++) { 00035 patlite_y = !(i % 2); 00036 wait_ms(100); 00037 } 00038 wait_ms(1000); 00039 } 00040 00041 patlite_y = 1; 00042 wait(1); 00043 patlite_y = 0; 00044 00045 00046 while(1) { 00047 uint8_t avail; 00048 uint8_t queued; 00049 00050 for(uint8_t i=0; i<queued; i++) { 00051 uint8_t channel; 00052 uint8_t type; 00053 uint8_t values[8]; 00054 int64_t offset; 00055 int32_t value; 00056 00057 // RXキューから点灯要求を取り出す 00058 uint8_t ret = sakuraio.dequeueRx(&channel, &type, values, &offset); 00059 value = *((int32_t *)values); 00060 if(ret == 0x01) { 00061 // 取り出せたらチャンネルIDを元に動作振り分け 00062 // https://gist.github.com/misodengaku/17b8194dcd0c3038ea5ce7f60ef04072 00063 if (channel < 7) { 00064 // tentou 00065 if (value == 1) { 00066 patlite_map[channel] = 1; 00067 sakuraio.enqueueTx((uint8_t)channel, (int32_t)1); 00068 } else { 00069 patlite_map[channel] = 0; 00070 sakuraio.enqueueTx((uint8_t)channel, (int32_t)0); 00071 } 00072 } 00073 00074 } 00075 } 00076 counter++; 00077 if (counter % 100 == 0) { 00078 sakuraio.enqueueTx(24, counter); 00079 status_led = !status_led; 00080 } 00081 sakuraio.getTxQueueLength(&avail, &queued); 00082 if(queued >= 30) { 00083 sakuraio.clearTx(); 00084 } else if(queued >= 5) { 00085 sakuraio.send(); 00086 } 00087 00088 wait_ms(10); 00089 } 00090 00091 } 00092
Generated on Wed Jul 13 2022 19:37:08 by
1.7.2