Skip to content

Instantly share code, notes, and snippets.

@jstrassburg
Created October 31, 2018 20:28
Show Gist options
  • Save jstrassburg/935e55f1fb760fee6dd64b19bad63f3b to your computer and use it in GitHub Desktop.
Save jstrassburg/935e55f1fb760fee6dd64b19bad63f3b to your computer and use it in GitHub Desktop.
My moving eyeball pumpkin Arduino code.
#include <Servo.h>
const int SERVO_COUNT = 10;
Servo servos[SERVO_COUNT];
const int SERVO_MIN = 40;
const int SERVO_MAX = 180;
void setup() {
for (int i = 0 ; i < SERVO_COUNT ; i += 1) {
servos[i].attach(i + 2);
delay(100); // slight delay to prevent current draw reset on startup
}
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop() {
halloween();
}
void halloween(){
int servo = random(0, SERVO_COUNT);
set_servo_rand(servo);
int del = random(100, 500);
delay(del);
}
void set_servo_rand(int servo) {
int pos = random(SERVO_MIN, SERVO_MAX);
servos[servo].write(pos);
int del = random(0, 500);
delay(del);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment