Good evening everyone, I am creating an automatic fish feeder using a servomotor, all powered by an esp8266 and HA obviously.
I would need a script that every 3 hours starting from 9 am (9:00 - 12:00 - 15:00) moves the servomotor incrementally by 20, 20, 10 respectively.
In practice at the end of the first day it must go from -100 to -50, the following day to 0 etc until it reaches the maximum and goes back.
I can move the servo at a given time to position x but I can’t implement what would be this cycle in Arduino:
void startFeedern(int number){
int pos;
if(number==1){
for(pos=posfinale;pos<=posfinale+20;pos+=1){
Servo1.write(pos);
}
}else if(number==2){
for(pos=posfinale;pos<=posfinale+20;pos+=1){
Servo1.write(pos);
}
}else if(number==3){
for(pos=posfinale;pos<=posfinale+10;pos+=1){
Servo1.write(pos);
}
}
posfinal=pos;
}
Can someone help me?
this is actually my code:
time:
- platform: homeassistant
id: homeassistant_time
- platform: sntp
# ...
on_time:
- minutes: /5
then:
- servo.write:
id: my_servo
level: 0
font:
- file: "arial.ttf"
id: my_font
size: 20
# Example configuration entry
i2c:
sda: D1
scl: D2
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
reset_pin: D0
address: 0x3C
lambda: |-
it.strftime(0, 60, id(my_font), TextAlign::BASELINE_LEFT, "%H:%M", id(homeassistant_time).now());
# Example configuration entry
servo:
- id: my_servo
output: pwm_output
# Example output platform
# On ESP32, use ledc output
output:
- platform: esp8266_pwm
id: pwm_output
pin: D8
frequency: 50 Hz
number:
- platform: template
name: Servomotore
min_value: -100
max_value: 100
step: 5
set_action:
then:
- servo.write:
id: my_servo
level: !lambda 'return x / 100.0;'