Created
October 31, 2018 20:28
-
-
Save jstrassburg/935e55f1fb760fee6dd64b19bad63f3b to your computer and use it in GitHub Desktop.
My moving eyeball pumpkin Arduino code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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