Created
April 8, 2022 07:53
-
-
Save cowdinosaur/970f60971da81b17e9bced8e103965ff to your computer and use it in GitHub Desktop.
Arduino Neopixel basic code
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 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