millerman4487
Published © CC BY-NC-SA

Simple Record and Playback

Record and play back a few seconds of input stored in EEPROM.

IntermediateProtip15 minutes9,961

Things used in this project

Story

Read more

Schematics

Schematic

Code

Code

Arduino
#include <Servo.h>
#include <EEPROM.h>//used to store recorded values

Servo myServo;

float resolution = 1000;//MUST be less than EEPROM.length() (check serial monitor)
float recordTime = 5; //delay time
bool recording = false;

void setup() {
  pinMode(13, OUTPUT); //status led
  pinMode(2, OUTPUT);
  myServo.attach(3);

  Serial.begin(9600);
  digitalWrite(2, HIGH);
  //Serial.println(EEPROM.length());
}

void loop() {
  if (recording == true) {//record
    for (int i = 1; i <= resolution; i++) {
      digitalWrite(13, HIGH); //light status led
      int val = map(analogRead(A0), 0, 1023, 0, 180);

      EEPROM.write(i, val);
      //Serial.println(EEPROM.read(i));
      myServo.write(val);
      delay(recordTime);
    }

    digitalWrite(13, LOW); //turn off status led
    delay(1000);//give time for person
    recording = false;
  }
  else {
    for (int i = 1; i <= resolution; i++) {//playback
      if (digitalRead(2) == 0) {//stop playback and record new values
        recording = true;
        break;
      }
      int readval = EEPROM.read(i);
      myServo.write(readval);
      //Serial.println(readval);
      delay(recordTime);
    }

    digitalWrite(13, HIGH); //show a new repeat
    delay(100);
    digitalWrite(13, LOW);
  }
}

Credits

millerman4487

millerman4487

10 projects • 57 followers

Comments