Stap 4: Testen en codering
De verbindingen zijn vrij eenvoudig.
Een weerstand tussen de GND en A0 op de analoge 0 standaard plaatsen Dit helpt Arduino aan het echte ding gevoel en niet zomaar een inmenging die radiosignalen enz.
Begane grond uit de stekker om er een deel van de Arduino.
Breng kanaal links of rechts van de stekker Arduino A0
De led strip + 5 aan VCC en GND op GND. datakabel gaat naar de Arduino pin 6.
Als u vragen hebt, vraag het ons.
Merk op dat u NeoPixel.h bibliotheek moet. Vinden van GitHub.
#include <Adafruit_NeoPixel.h>#include <avr/power.h>#define PIN 6Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);void setup() { Serial.begin(9600); strip.begin(); strip.show(); // Initialize all pixels to 'off' }void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue);//Just for the calipration if(sensorValue > 10) { rainbowCycle(0); } if(sensorValue >30){theaterChase(strip.Color(255,0,0),10); theaterChase(strip.Color(255,0,0),10); theaterChase(strip.Color(0,0,255),10); } if(sensorValue >40){ colorWipe(strip.Color(255,0,0),10); colorWipe(strip.Color(0,255,0),10); colorWipe(strip.Color(0,0,255),10); } }//this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*1; j++) { // 1 cycle of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } //Theatre-style crawling lights. void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<5; j++) { //do 5 cycles of chasing for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show(); delay(wait); for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } } }// Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i