Last active
November 11, 2022 03:38
-
-
Save todocono/275893bd8538a73f4163ab89fe342c76 to your computer and use it in GitHub Desktop.
This file contains 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
/* This is a code example for Arduino, to be used on Recitation 7 | |
You need to have installed SerialRecord and FastLED libraries. | |
It requires NeoPixel WS2812 at pin 3 | |
Interaction Lab | |
IMA NYU Shanghai | |
2022 Fall | |
*/ | |
#include "SerialRecord.h" | |
#include <FastLED.h> | |
#define NUM_LEDS 60 // How many leds in your strip? | |
#define DATA_PIN 3 // Which pin are you connecting Arduino to Data In? | |
CRGB leds[NUM_LEDS]; | |
// Change this number to the number of values you want to receive | |
SerialRecord reader(4); | |
void setup() { | |
Serial.begin(9600); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // Initialize | |
FastLED.setBrightness(10); // BEWARE: external power for full (255) | |
//further info at https://learn.adafruit.com/adafruit-neopixel-uberguide/powering-neopixels | |
} | |
void loop() { | |
if (reader.read()) { | |
int n = reader[0]; | |
int r = reader[1]; | |
int g = reader[2]; | |
int b = reader[3]; | |
leds[reader[0]] = CRGB(reader[1], reader[2], reader[3]); // Prepare the color information using CRGB( Red, Green, Blue | |
FastLED.show(); // Pass the information of color to the LED | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment