#include <Servo.h>
#include <LiquidCrystal.h>
#include <TM1637.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo arm; // Create a "Servo" object called "arm"
TM1637 tm(4, 5);
float pos = 0.0; // Variable where the arm's position will be stored (in degrees)
float step = 0.5; // Variable used for the arm's position step
void setup() {
// put your setup code here, to run once:
arm.attach(3); // Attach the arm to pin 3
arm.write(pos); // Initialize the arm's position to 0 (leftmost)
pinMode(A1, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
lcd.begin(16, 2);
tm.init();
tm.set(BRIGHT_TYPICAL);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(A1) == LOW) {
if (pos == 0) {
for (float x = 0 ; x <= 180; x+=step ) {
pos = x;
arm.write(pos);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(pos);
dsply();
delay(100);
}
}
else {
for (float x = 180 ; x >= 0; x-=step ) {
pos = x;
arm.write(pos);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(pos);
dsply();
delay(100);
}
}
}
}
void dsply() {
int position = (int)pos;
float decimal = pos - (int)pos;
int dec_int = (int)(decimal * 10);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(decimal);
lcd.setCursor(8, 1);
lcd.print(dec_int);
tm.display(0, (position/100) % 10);
tm.display(1, (position/10) % 10);
tm.display(2, position % 10);
tm.display(3, dec_int);
}