Hi!
I just cant make this code to work, what am I doing wrong? I whant the serve to run at the same time as the LED-code runs.
BR Brandon Lane
#include <Servo.h>
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
#define PIN 2
#define NUMPIXELS 1
Adafruit_NeoPixel led_strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Servo servo;
int val;
unsigned long previousMillis_1 = 0; // will store last time LED was updated
unsigned long previousMillis_2 = 0;
// constants won't change :
const long interval_1 = 1000; // interval at which to blink (milliseconds)
const long interval_2 = 500;
void setup() {
servo.attach(9); // attaches the servo on pin 9 to the servo object
led_strip.begin();
}
void loop() {
led_servo_crystal();
}
uint32_t led_servo_crystal() {
uint16_t i, j;
unsigned long currentMillis_2 = millis();
unsigned long currentMillis_3 = millis();
unsigned long currentMillis_1 = millis();
if (currentMillis_1 - previousMillis_1 >= interval_1) {
previousMillis_1 = currentMillis_1;
// tryck in koden här
val = random(65,100);
servo.write(val);
}
if (currentMillis_2 - previousMillis_2 >= interval_2) {
previousMillis_2 = currentMillis_2;
for(j=0; j<256; j++) {
for(i=0; i<led_strip.numPixels(); i++) {
led_strip.setPixelColor(i, Wheel((i+j) & 255));
}
led_strip.show();
}
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return led_strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return led_strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return led_strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}