I have a code, the neopixels are in order and when I push the button, the servo should move. But there is a problem when I combine the 2 codes in 1 file, the servo doesn't want to work properly. Can someone help me please? - YouTube
#include <Adafruit_NeoPixel.h> // importeren vanuit bibliotheek
Adafruit_NeoPixel tira = Adafruit_NeoPixel(8, 5, NEO_GRB + NEO_KHZ800); // random naam geven; hier "tira"
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int button = 3; // The button will be on Pin 7
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pos, OUTPUT);
pinMode(button, INPUT);
digitalWrite (button, LOW);
tira.begin(); // inicializacion de la tira
tira.show(); // muestra datos en pixel
if (digitalRead(button) == LOW)
for(pos = 0; pos < 90; pos += 90) // goes from 0 degrees to 90 degrees
{ // in steps of degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
// waits 1s for the servo to reach the position
}
if (digitalRead(button) == HIGH)
for(pos = 90; pos>=90; pos-=90) // goes from 90 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 50ms for the servo to reach the position
}
myservo.detach();
}
void loop()
{
tira.setBrightness(10);
for(int i = 0; i < 8; i++){ //
tira.setPixelColor(i, 0, 255, 0);
tira.show();
delay(500);
tira.setPixelColor(i, 0, 0, 0); /
tira.show();
}
}