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:
- 1:1de917dde4ed
- Parent:
- 0:943dfa56009a
--- a/main.cpp Sat Nov 07 13:40:03 2020 +0000 +++ b/main.cpp Sun Nov 22 12:01:50 2020 +0000 @@ -1,149 +1,62 @@ #include "mbed.h" +#include <stdlib.h> -RawSerial pc(USBTX,USBRX,115200 * 4); -DigitalOut bLed(LED1); -InterruptIn user(PC_13); - -bool doLedStop = true; +#include "WS2812B.h" -#include "midi.h" -#include "LED.h" -#include "hale_sola.h" -#include "doctorX.h" -#include "lupin.h" -#include "spin_kick.h" -#include "singsingsing.h" -#include "starwars.h" -#include "yozakura.h" -#include "sunshineaura.h" -#include "sanadamaru.h" -#include "jurassic.h" +#define BUF 60 +#define BUF2 42 -Thread *LedTh; -Thread LEDSend; -Thread PC; - -char pcCommand; -char color[3]; -double alpha; -int pcCount = 0; - -void PcRead(); - -int musicNum = -1; - -enum Mode { - Nucleo,Straight +int buf[3] = {BUF,BUF,BUF2}; +WS2812B tape[2] = { + WS2812B(PB_0,BUF), + WS2812B(PC_1,BUF)/*, + WS2812B(PC_0,BUF2)*/ }; -Mode mode = Nucleo; - +int brightness[2]; +Thread sendTh; -void Test() -{ - //ModelReq(); - //Start(); - //MDRStart(); - bLed=1; - pc.putc(0xFA); +uint32_t colors[] = {0xFF0000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF}; -} - -void MCLed() +void SendingLED() { - beatTime = 60/120.0; - - calcBar = 0; - ledT.reset(); - ledT.start(); - while (1) { - tape[0].Write(0xFFFFFF); - FlowLED2(4,0,0xFFFFFF,1,0); + for (int t = 0; t < 2; t++) tape[t].Send(); + wait_us((1000 / 60)*1e3); } } - int main() { - printf("\rElectone LED Controller\n\r"); - - user.fall(Test); - - LEDSend.start(SendingLED); + printf("\r2020 S-Home Christmas!!!\n\r"); + sendTh.start(SendingLED); for (int t = 0; t < 2; t++) tape[t].Write(0xFFFFFF); wait_us(0.3 * 1e6); for (int t = 0; t < 2; t++) tape[t].Write(0); - Thread Midi; - //Midi.start(MidiTh); - //ms.attach(MidiTh,RawSerial::RxIrq); - pc.attach(PcRead,RawSerial::RxIrq); - //PC.start(PcRead); - wait(0.1); - - while (1) { - if (mode == Straight) { - if (LedTh->get_state() == 1 && doLedStop) LedTh->terminate(); - uint32_t c = color[0] << 16 | color[1] << 8 | color[2]; - for (int t = 0; t < 2; t++) tape[t].Write(c); - - for (int t = 0; t < 2; t++) tape[t].Brightness(alpha); - } else { - if (doRhythm) { - if (LedTh->get_state() == 16) { - pc.putc(0xFA); - LedTh = new Thread(); - if (musicNum == 1) LedTh->start(SingSingSing); - else if (musicNum == 2) LedTh->start(DoctorX); - else if (musicNum == 3) LedTh->start(Yozakura); - else if (musicNum == 4) LedTh->start(Lupin); - else if (musicNum == 5) LedTh->start(Sunshineaura); - else if (musicNum == 6) LedTh->start(StarWars); - else if (musicNum == 7) LedTh->start(HaleSola); - else if (musicNum == 8) LedTh->start(Spin_kick); - else if (musicNum == 9) LedTh->start(Sanadamaru); - else if (musicNum == 10) LedTh->start(Jurassic); - } - } else { - if (musicNum == 0) { - if (LedTh->get_state() == 16) { - LedTh = new Thread(); - LedTh->start(MCLed); - } - } else if (LedTh->get_state() == 1 && doLedStop) { - pc.putc(0xFC); - LedTh->terminate(); - for (int t = 0; t < 2; t++) tape[t].Clear(BUF); - } + double sita[2][BUF] = {0}; + uint32_t c[2][BUF] = {0}; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < BUF; j++) { + sita[i][j] = fmod(rand()/1000.0,(double)PI * 3);// + PI * (j % 3);//(,PI); + c[i][j] = rand() % 7; + } + } + //float sita = 0; + while (1) { + for (int t=0; t < 2; t++) { + for (int i = 0; i < buf[t]; i++) { + if (sita[t][i] == 0) c[t][i] = rand() % 7; + + float s = 0; + if (sita[t][i] > 0 && sita[t][i] < PI)s = sin(sita[t][i]); + tape[t].Write(i,colors[c[t][i]],s); + + sita[t][i] += 0.03f; + if (sita[t][i] > PI * 3) sita[t][i] = 0; } } - } -} - -void PcRead() -{ - if (pc.readable()) { - char data = pc.getc(); - - if (data >= 0x80) { // 開始バイト - if (data >= 0x90) mode = Straight; - else if (data >= 0x80) mode = Nucleo; - pcCommand = data; - pcCount = 0; - - } else { // データバイト - if (pcCommand == 0x80) { - musicNum = data; - } else if (pcCommand == 0x91 && pcCount < 3) { - color[pcCount] = data << 1; - } else if (pcCommand == 0x92 && pcCount < 1) { - alpha = (double)data / 127; - } else { - //bLed = 0; - } - pcCount++; - } + wait_us(0.01 * 1e6); } } \ No newline at end of file