Description:
I built a record and play back device which uses one potentiometer to decide the state it is in, either recording or playing back. When in recording state the second potentiometer is used to record the pattern. In the current implementation the input is recorded as 0's and 1's and the output is LED HIGH or LOW. It can be extended to record analog values and play those back. I am also excited about this because it can be modified to record patterns from other analog sensors.
Components Used:
2 potentiometer
1 arduino
1 220 ohm resistors
1 led
Code
int pattern[100];
int position = 0;
int high = 255;
int stateIn = 0;// on state(playback or record)
int recordIn = 1;// record state 01010
int aOut = 9;
// Two states
// - record
// - playback
boolean inRecordState = false;
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(aOut, OUTPUT);
initializePosition();
Serial.begin(9600);
}
void loop()
{
int stateInVal = analogRead(stateIn);
if(stateInVal < 512)
{
// in playback state?
if(!inRecordState)
{
glowLed();
updatePosition();
}
else
{
Serial.println("");
Serial.println("Entered Playback State");
// state change
inRecordState = false;
// position reset
position = 0;
glowLed();
updatePosition();
}
}
else
{
if(inRecordState)
{
recordPattern();
updatePosition();
}
else
{
Serial.println("");
Serial.println("Entered Record State");
inRecordState=true;
position = 0;
recordPattern();
updatePosition();
}
}
delay(100);
}
void glowLed()
{
if(pattern[position] == 0)
{
Serial.print("0");
analogWrite(aOut,0);
}
else
{
Serial.print("1");
analogWrite(aOut,255);
}
}
void recordPattern()
{
int recordInVal = analogRead(recordIn);
if(recordInVal<512)
{
Serial.print("0");
pattern[position] = 0;
analogWrite(aOut,0);
}
else
{
Serial.print("1");
pattern[position] = 1;
analogWrite(aOut,255);
}
}
void updatePosition()
{
if(position < 99)
{
position++;
}
else
{
position = 0;
}
}
void initializePosition()
{
for (int i=0; i < 99 ; i++)
{
pattern[i]=1;
}
}
- Login to post comments