/* Sweep+poti
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 22 Jun 2023
by Mihael
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#include <Servo.h>
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int x = 100;
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 5
int poti = 0; // variable to store the analogPin->A0 value ->read
void setup() {
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
poti = analogRead(analogPin)/6; // read the input pin
//x = x + 10;
x = poti;
if (x > 179) {
x=0;
}
for (pos = 0; pos <= x; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for (pos = x; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
Serial.print("pos->value: ");
Serial.print(x);
Serial.print(" ");
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print("poti->value: ");
Serial.print(poti);
Serial.print(" ");
Serial.println();
int analogValue = analogRead(A1);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temp= ");
Serial.print(celsius);
Serial.println();
//delay(3);
}