Created
May 13, 2021 05:43
-
-
Save CUEICHI/beae3fa2cc04dfac4cb3995050927be7 to your computer and use it in GitHub Desktop.
m5atom のLEDを OSCからコントロールする fastledと arduinoOSCを入れてください.
This file contains hidden or 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
| /* | |
| OSC Test -- for M5Atom | |
| config: | |
| Waiting PORT 5005 | |
| OSC Command | |
| /msg MSG to serialport | |
| /clean clear LED | |
| /led , LED_POS,R,G,B | |
| */ | |
| #include <ArduinoOSC.h> | |
| #include <FastLED.h> | |
| #define SEC 1000 | |
| #define NUM_LEDS 25 | |
| #define DATA_PIN 27 | |
| #define MAX_BRIGHTNESS 40 | |
| CRGB leds[NUM_LEDS]; | |
| // WIFI | |
| #define SSID "SSID" | |
| #define WIFIPW "PASSWORD" | |
| // OSC | |
| #define PORT 5005 | |
| // hookされる関数 | |
| void onOscReceived(const OscMessage& m) | |
| { | |
| Serial.print(m.remoteIP()); Serial.print(" "); | |
| Serial.print(m.remotePort()); Serial.print(" "); | |
| Serial.print(m.size()); Serial.print(" "); | |
| Serial.print(m.address()); Serial.print(" "); | |
| Serial.print(m.arg<int>(0)); Serial.println(); | |
| //Serial.print(m.arg<int>(1)); Serial.print(" "); | |
| //Serial.print(m.arg<int>(2)); Serial.print(" "); | |
| //Serial.print(m.arg<int>(3)); Serial.println(); | |
| } | |
| int pos, r, g, b; | |
| // hookされる関数 | |
| void onClnMsg(const OscMessage& m) { | |
| Serial.println("Clean buffer"); | |
| fill_solid(&leds[0], 26, CRGB::Black); | |
| FastLED.show(); | |
| pos = r = g = b = 0; | |
| } | |
| void setup() { | |
| Serial.begin(115200); | |
| FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
| fill_solid(leds, 24, CRGB(25, 0, 0)); | |
| FastLED.show(); | |
| WiFi.begin(SSID, WIFIPW); | |
| while (WiFi.status() != WL_CONNECTED) { | |
| delay(1000); | |
| Serial.print("."); | |
| } | |
| Serial.print("\n Connected. IPAddr:"); | |
| Serial.println(WiFi.localIP()); | |
| delay(SEC); | |
| OscWiFi.subscribe(PORT, "/msg", onOscReceived); | |
| OscWiFi.subscribe(PORT, "/clean", onClnMsg) ; | |
| OscWiFi.subscribe(PORT, "/led", pos, r, g, b); // hookして変数に代入 | |
| fill_solid(leds, 24, CRGB(0, 0, 0)); | |
| FastLED.show(); | |
| } | |
| int opos = -1, og = -1 ; | |
| void loop() { | |
| // put your main code here, to run repeatedly: | |
| // 代入した変数をそのままチェックして利用する | |
| leds[pos].setRGB(r, g, b); | |
| FastLED.show(); | |
| // Serial.print("LED: "); | |
| // Serial.print(pos); Serial.print(" "); | |
| // Serial.print(r); Serial.print(" "); | |
| // Serial.print(g); Serial.print(" "); | |
| // Serial.println(b); | |
| OscWiFi.update(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment