Created
September 20, 2017 23:02
-
-
Save monteslu/482b1c692afcf228d2d165ddec68c816 to your computer and use it in GitHub Desktop.
webusb + neopixels
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
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define PIN 6 | |
// Parameter 1 = number of pixels in strip | |
// Parameter 2 = Arduino pin number (most are valid) | |
// Parameter 3 = pixel type flags, add together as needed: | |
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) | |
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) | |
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) | |
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) | |
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(256, PIN, NEO_GRB + NEO_KHZ800); | |
#include <WebUSB.h> | |
WebUSB WebUSBSerial(1, "webusb.github.io/arduino/demos"); | |
#define Serial WebUSBSerial | |
const int redPin = 9; | |
const int greenPin = 10; | |
const int bluePin = 11; | |
int color[3]; | |
int index; | |
void setup() { | |
while (!Serial) { | |
; | |
} | |
Serial.begin(9600); | |
Serial.write("Sketch begins.\r\n"); | |
Serial.flush(); | |
index = 0; | |
strip.begin(); | |
} | |
void loop() { | |
if (Serial && Serial.available()) { | |
color[index++] = Serial.read(); | |
if (index == 3) { | |
for(uint16_t i=0; i<strip.numPixels(); i++) { | |
strip.setPixelColor(i, strip.Color( color[0], color[1], color[2] )); | |
} | |
strip.show(); | |
// | |
// analogWrite(redPin, color[0]); | |
// analogWrite(greenPin, color[1]); | |
// analogWrite(bluePin, color[2]); | |
Serial.print("Set LED to "); | |
Serial.print(color[0]); | |
Serial.print(", "); | |
Serial.print(color[1]); | |
Serial.print(", "); | |
Serial.print(color[2]); | |
Serial.print(".\r\n"); | |
Serial.flush(); | |
index = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment