SERVO ANGLE RECORD

Servo Record

#include <Servo.h>
#include <EEPROM.h>
#define buttonPin0 2
#define buttonPin1 3
#define ledPin1 6
#define ledPin2 7
#define ledPin3 8
#define ledPin4 9
int sensorPin = A0;
int sensorValue = 0;
int buttonPushCounter=0;
int buttonState = 0;
int lastButtonState = 0;
Servo head;
byte angka1;
byte angka2;
byte angka3;
byte angka4;
void setup()
{
head.attach(10);
head.write(80);
pinMode(sensorPin,INPUT);
pinMode(buttonPin0, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
Serial.begin(9600);
}
unsigned long last = millis();
int on = 0;
void loop(){
{
buttonState = digitalRead(buttonPin0);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
if (millis() – last > 1000) {
buttonPushCounter++;
Serial.println(“on”);
Serial.print(“number of button pushes: “);
Serial.println(buttonPushCounter);
}
last = millis();
}
}
}

lastButtonState = buttonState;

if (buttonPushCounter % 5 == 0) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);

}
if (buttonPushCounter % 5 == 1) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
}
if (buttonPushCounter % 5 == 2){
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
}
if (buttonPushCounter % 5 == 3) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
}
if (buttonPushCounter % 5 == 4) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
}

if ((buttonPushCounter % 5 == 1)&&(digitalRead(buttonPin1) == HIGH))
{
float sensorValue = analogRead(sensorPin);
int sudut = (sensorValue/1023)*180;
head.write(sudut);
EEPROM.write(1,sudut);

}
if ((buttonPushCounter % 5 == 2)&&(digitalRead(buttonPin1) == HIGH))
{
float sensorValue = analogRead(sensorPin);
int sudut = (sensorValue/1023)*180;
head.write(sudut);
EEPROM.write(2,sudut);
}
if ((buttonPushCounter % 5 == 3)&&(digitalRead(buttonPin1) == HIGH))
{
float sensorValue = analogRead(sensorPin);
int sudut = (sensorValue/1023)*180;
head.write(sudut);
EEPROM.write(3,sudut);
}
if ((buttonPushCounter % 5 == 4)&&(digitalRead(buttonPin1) == HIGH))
{
float sensorValue = analogRead(sensorPin);
int sudut = (sensorValue/1023)*180;
head.write(sudut);
EEPROM.write(4,sudut);
}
if ((buttonPushCounter % 5 == 0)&&(digitalRead(buttonPin1) == LOW))
{

angka1 = EEPROM.read(1);
head.write(angka1);
Serial.print(angka1);
Serial.print(” “);
delay(1000);
angka2 = EEPROM.read(2);
head.write(angka2);
Serial.print(angka2);
Serial.print(” “);
delay(1000);
angka3 = EEPROM.read(3);
head.write(angka3);
Serial.print(angka3);
Serial.print(” “);
delay(1000);
angka4 = EEPROM.read(4);
head.write(angka4);
Serial.print(angka4);
Serial.println(” “);
delay(1000);
}
}