Skip to content

Instantly share code, notes, and snippets.

@cowdinosaur
Created April 8, 2022 07:53
Show Gist options
  • Save cowdinosaur/970f60971da81b17e9bced8e103965ff to your computer and use it in GitHub Desktop.
Save cowdinosaur/970f60971da81b17e9bced8e103965ff to your computer and use it in GitHub Desktop.
Arduino Neopixel basic code
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 8
#define NUMPIXELS 16 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int pressed = 0;
void setup() {
pixels.begin();
Serial.begin(9600);
pinMode(2, INPUT);
}
void loop() {
pressed = digitalRead(2);
if (pressed == 1) { // not pressed
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, 0, 0, 0);
pixels.show();
}
Serial.println("Off");
}
else {
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, 255, 0, 0);
pixels.show();
}
Serial.println("On");
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment