You are on page 1of 6

#include <Servo.

h>

#define up 2

#define down 3

#define record 4

#define play 5

Servo myservo;

uint16_t pos = 0;

boolean dataUp = false;

boolean dataDown = false;

bool dataRec = false;

boolean stateUp = false;

boolean stateDown = false;

boolean stateRec = false;

uint8_t Rec [5];

int posisiData = 0 ;

void setup() {

Serial.begin (9600);

myservo.attach(9);

myservo.write(0);
pinMode (up, INPUT_PULLUP);

pinMode (down, INPUT_PULLUP);

pinMode (record, INPUT_PULLUP);

pinMode (play, INPUT_PULLUP);

void loop() {

dataUp = digitalRead(up);

dataDown = digitalRead(down);

dataRec = digitalRead(4);

if (dataUp == LOW && stateUp == false){

pos = pos + 1;

myservo.write (pos);

stateUp = true;

if (dataUp == HIGH){

stateUp = false;

if (dataDown == LOW && stateDown == false){

pos = pos - 1;

myservo.write (pos);

stateDown = true;

if (dataDown == HIGH){
stateDown = false;

if (pos >= 180){ pos = 180;}

if (pos <= 0){ pos = 0;}

if (dataRec == false && stateRec == false){

Rec [posisiData] = pos;

posisiData = posisiData + 1;

stateRec = true;

if (dataRec == HIGH){

stateRec = false;

/*

Serial.print ("derajat = "); Serial.print (pos);

Serial.print (" Kondisi tombol Up = "); Serial.print (dataUp);

Serial.print (" Kondisi tombol Down = "); Serial.println (dataDown);

*/

for (int x = 0; x <5; x++){

Serial.print (Rec[x]);
Serial.print (" ");

Serial.print (pos);

if (digitalRead(play) == LOW){

Serial.println ("Play..");

delay (1000);

if (Rec[0] < Rec[1]){

for (pos = Rec[0]; pos <= Rec[1]; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

Serial.println (pos);

myservo.write (pos);// tell servo to go to position in variable 'pos'

delay(100); // waits 15ms for the servo to reach the position

Serial.println ("Step done..");

delay (1000);

for (pos = Rec[1]; pos <= Rec[2]; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

Serial.println (pos);

myservo.write (pos);// tell servo to go to position in variable 'pos'


delay(100); // waits 15ms for the servo to reach the position

Serial.println ("Step done..");

delay (1000);

for (pos = Rec[2]; pos <= Rec[3]; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

Serial.println (pos);

myservo.write (pos);// tell servo to go to position in variable 'pos'

delay(100); // waits 15ms for the servo to reach the position

Serial.println ("Step done..");

delay (1000);

for (pos = Rec[3]; pos <= Rec[4]; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

Serial.println (pos);

myservo.write (pos);// tell servo to go to position in variable 'pos'

delay(100); // waits 15ms for the servo to reach the position

Serial.println ("Step done..");

delay (1000);
for (pos = Rec[4]; pos <= Rec[5]; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

Serial.println (pos);

myservo.write (pos);// tell servo to go to position in variable 'pos'

delay(100); // waits 15ms for the servo to reach the position

delay (1000);

Serial.println ("done..");

while (1);

Serial.println();