Skip to content

Commit

Permalink
Supplementary power input
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrjwegrzyn committed Apr 18, 2022
1 parent 36e669e commit d56b6ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
foreign/
*.jar
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Arduino-compatibile ESP8266 module's firmware for WiFi connection, photoresistor
* 1x resistor 500 Ohm
* 1x LED
* 1x button switch
* 1x capacitor 2.2 mF
* 1x rectifier diode

### Circut
![circut.png](docs/circut.png)

### Description
Unfortunatelly, ESP8266 does not provide 5V output pins, so there is external power input to circut. 5V input is required to power on microservo and can be used as input standalone (via Vin pin on ESP8266).
### Functionalities
* WiFi connectivity, broadcast and simple management
* photoresistor's resistance measurement
Expand Down
Binary file modified docs/circut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 14 additions & 10 deletions window-blinds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ static const uint8_t CMD_GET_RES = 0x10;
static WiFiUDP _udp_instance;
static Servo _microservo;

static uint8_t SRV_ROT_RIGHT = 180;
static uint8_t SRV_ROT_LEFT = 0;
static uint8_t SRV_ROT_NONE = 89;

static bool _configured = false;
static uint16_t _id = 0x0;
static uint8_t _srv_pos = 0;
Expand Down Expand Up @@ -90,23 +94,23 @@ bool handle_pkt() {
*/
void srv_time_conf() {
Serial.println("Configuration has started");
while (analogRead(D2) > 0) {
while (analogRead(D2) < 1) {
blink_led(1, STD_DELAY_XS);
}

while (analogRead(D2) < 1) {
while (analogRead(D2) > 0) {
blink_led(1, STD_DELAY_XS);
}

blink_led(3, STD_DELAY_S);
uint32_t start_time = millis();
_microservo.write(180);
while (analogRead(D2) > 0) {
_microservo.write(SRV_ROT_RIGHT);
while (analogRead(D2) < 1) {
delay(STD_DELAY_XXS);
continue;
}

_microservo.write(90);
_microservo.write(SRV_ROT_NONE);
_srv_time = millis() - start_time;
blink_led(1, STD_DELAY_M);
_srv_pos = 0xFF;
Expand Down Expand Up @@ -204,7 +208,7 @@ bool set_params(char *params) {
*/
void set_ser_con() {
_microservo.attach(D4);
_microservo.write(90);
_microservo.write(SRV_ROT_NONE);
}


Expand All @@ -214,14 +218,14 @@ void set_ser_con() {
bool set_ser_pos(uint8_t pos) {
uint32_t rot_time = static_cast<uint32_t>((_srv_time * abs(_srv_pos - pos)) / 255);
if (_srv_pos > pos) {
_microservo.write(0);
_microservo.write(SRV_ROT_LEFT);
}
else if (_srv_pos < pos) {
_microservo.write(180);
_microservo.write(SRV_ROT_RIGHT);
}

delay(rot_time);
_microservo.write(90);
_microservo.write(SRV_ROT_NONE);
_srv_pos = pos;
return true;
}
Expand Down Expand Up @@ -283,7 +287,7 @@ void loop() {
Serial.println("Microservo is not configured");
}

if (analogRead(D2) > 0) {
if (analogRead(D2) < 1) {
srv_time_conf();
}

Expand Down

0 comments on commit d56b6ba

Please sign in to comment.