本帖最后由 王尼玛1 于 2020-7-11 11:29 编辑
- <div class="blockcode"><blockquote>
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define BUTTON_PIN2 2
- #define BUTTON_PIN3 3
- #define BUTTON_PIN4 4
- #define PIXEL_PIN 9
- #define PIXEL_COUNT 60
- int pixelFormat = NEO_GRB + NEO_KHZ800;
- Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- pinMode(2, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(4, INPUT_PULLUP);
- pinMode(9, OUTPUT);
- Serial.begin(9600);
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
- clock_prescale_set(clock_div_1);
- #endif
- for (int i = 0; i < PIXEL_COUNT; i++)
- {
- strip.setPixelColor(i, strip.Color(0, 0, 0));
- strip.show();
- }
- delay(500);
- }
- void loop() {
- if (digitalRead(BUTTON_PIN2) == 0)
- RED() ;
- else if (digitalRead(BUTTON_PIN3) == 0)
- GREED();
- else if (digitalRead(BUTTON_PIN4) == 0)
- BLUE();
- else {
- for (int i = 0; i < PIXEL_COUNT; i++)
- {
- strip.setPixelColor(i, strip.Color(0, 0, 0));
- strip.show();
- }
- }
- }
- void RED() {
- for (int i = 0; i < PIXEL_COUNT; i++)
- {
- strip.setPixelColor(i, strip.Color(255, 0, 0));
- strip.show();
- }
- }
- void GREED() {
- for (int i = 0; i < PIXEL_COUNT; i++)
- {
- strip.setPixelColor(i, strip.Color(0, 255, 0));
- strip.show();
- }
- }
- void BLUE() {
- for (int i = 0; i < PIXEL_COUNT; i++)
- {
- strip.setPixelColor(i, strip.Color(0, 0, 255));
- strip.show();
- }
- }
复制代码
|