Browse Source

fix led and pulse

main
Hendrik Langer 7 years ago
parent
commit
bec7597a3f
  1. 2
      software/platformio.ini
  2. 7
      software/src/coin.cpp
  3. 1
      software/src/coin.h
  4. 4
      software/src/hardware.h
  5. 29
      software/src/led.cpp
  6. 3
      software/src/shelf.cpp

2
software/platformio.ini

@ -16,7 +16,7 @@ board_f_cpu = 160000000L
board_f_flash = 80000000L
framework = arduino
;build_flags = -DASYNC_TCP_SSL_ENABLED=1
build_flags = -fexceptions
build_flags = -fexceptions -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
lib_deps =
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/me-no-dev/AsyncTCP.git

7
software/src/coin.cpp

@ -39,10 +39,15 @@ void Coin::setup(void) {
}
int Coin::getMoney() {
if (millis() - lastUpdate <= 200) delay(200); // make sure to wait for the last pulse
while (millis() - lastUpdate <= 150) delay(150); // make sure to wait for the last pulse
return pulseCounter*5;
}
int Coin::isMoneyInserted() {
if (millis() - lastUpdate <= 1000) return pulseCounter*5;
else return 0;
}
void Coin::setZero() {
pulseCounter=0;
}

1
software/src/coin.h

@ -6,6 +6,7 @@ class Coin {
Coin(void);
void setup(void);
int getMoney(void);
int isMoneyInserted(void);
void setZero(void);
void subtractMoney(int);
private:

4
software/src/hardware.h

@ -21,7 +21,7 @@ static constexpr bool PROGMEM MQTT_SECURE = true;
static const char* PROGMEM mqtt_username = "vending";
static const char* PROGMEM mqtt_password = "password";
static constexpr uint8_t PROGMEM COIN_PULSE_PIN = 15;
static constexpr uint8_t PROGMEM COIN_PULSE_PIN = 36;
#endif /* _HARDWARE_H */
@ -29,7 +29,7 @@ static constexpr uint8_t PROGMEM COIN_PULSE_PIN = 15;
* __________
* 3v3 | | GND -- GND
* RST | | 23 -- Servo0
* 36 | | 22 -- Servo1
* PULSE-- 36 | | 22 -- Servo1
* 39 | | 01 (UART_TX)
* 34 | | 03 (UART_RX)
* 35 | | 21 -- Servo2

29
software/src/led.cpp

@ -4,6 +4,9 @@
#include "led.h"
#include "hardware.h"
#include "coin.h"
extern Coin coin;
using namespace std;
@ -49,6 +52,26 @@ void Led::loop_denied(void) {
void Led::loop_steady(void) {
fill_solid(leds, NUM_LEDS, color);
if (int moneyinserted = coin.isMoneyInserted()) {
fill_solid(leds, 8, CRGB::Black);
if (moneyinserted >= 5) {
leds[0] = CRGB::Yellow;
} if (moneyinserted >= 10) {
leds[1] = CRGB::Yellow;
} if (moneyinserted >= 20) {
leds[2] = CRGB::Yellow;
} if (moneyinserted >= 50) {
leds[3] = CRGB::Yellow;
} if (moneyinserted >= 75) {
leds[4] = CRGB::Yellow;
} if (moneyinserted >= 100) {
leds[5] = CRGB::Yellow;
} if (moneyinserted >= 150) {
leds[6] = CRGB::Yellow;
} if (moneyinserted >= 200) {
leds[7] = CRGB::Yellow;
}
}
}
void Led::changeAnimation(uint8_t num, uint16_t duration) {
@ -67,7 +90,11 @@ void Led::changeColor(uint8_t r, uint8_t g, uint8_t b) {
change = true;
}
void Led::changeBrightness(uint8_t brightness) {
FastLED.setBrightness(brightness);
if (brightness > 254) { // don't set first byte to 255 on tm1829
FastLED.setBrightness(254);
} else {
FastLED.setBrightness(brightness);
}
change = true;
}

3
software/src/shelf.cpp

@ -29,10 +29,11 @@ void Shelf::reload(void) {
void Shelf::dispenseTask(void* parameters) {
Serial.println("dispensing");
if (coin.getMoney() > 50) {
if (coin.getMoney() >= 50) {
item.at(num)->quantity--;
led.changeAnimation(1, 0);
pusher.push(num);
coin.subtractMoney(50);
vTaskDelay(500 / portTICK_PERIOD_MS);
led.changeAnimation(2, 0);
vTaskDelay(7000 / portTICK_PERIOD_MS);

Loading…
Cancel
Save