close-circle
Close

Sketch-a-letcha-ding-dong

A project log for Flashing Light Prize (1) Arduino Wave Generator

Turn me on like one of your French bulbs

VijeMiller 07/04/2017 at 22:270 Comments
// Flashing Light Prize (1)
// VijeMiller

#include <Servo.h>
Servo wave;

// Pot Analog Pin 0
int pot = A0;
// Delay Value
int val = 0;
// Servo Positions
int fro = 0;
int bac = 160;
int pos = 0;

void setup() {
  Serial.begin(9600);
  wave.attach(5);
  wave.write(pos);
}

void loop() {
  // Read Potentiometer
  val = analogRead(pot);
  // Print Value
  Serial.println(val);
  // Map Pot to Delay Value
  val = map(val, 0, 1023, 0, 20);
  // Print Value
  Serial.println(val);
  // Back
  for (pos = fro; pos <= bac; pos += 1)
  {
    wave.write(pos);
    delay(val);
  }
  // Forward
  for (pos = bac; pos >= fro; pos -= 1)
  {
    wave.write(pos);
    delay(val);
  }
}

Discussions