Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HX711.h"
- #include <TM1638plus.h>
- char odczyt[100];
- float ciezar;
- HX711 waga;
- #define STROBE_TM 4
- #define CLOCK_TM 6
- #define DIO_TM 7
- bool high_freq = false; //default false, If using a high freq CPU > ~100 MHZ set to true.
- //Constructor object (GPIO STB , GPIO CLOCK , GPIO DIO, use high freq MCU)
- TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM, high_freq);
- int ust=100;
- int otwPin = 3;
- int ustPin = A1;
- int prze = 10;
- float calibration_factor = 53270;
- uint8_t buttons = tm.readButtons();
- void setup() {
- Serial.begin(9600);
- pinMode(otwPin, INPUT_PULLUP);
- waga.begin(8, 9);
- waga.set_scale();
- waga.tare();
- waga.power_up();
- tm.displayBegin();
- pinMode(prze, OUTPUT);
- pinMode(ustPin, INPUT);
- }
- void loop() {
- uint8_t buttons = tm.readButtons();
- waga.set_scale(calibration_factor);
- ciezar=waga.get_units();
- dtostrf(ciezar,7,2,odczyt);
- if(buttons == 1)
- {
- ust = map(analogRead(ustPin), 0, 1000, 1400, 1600);
- if((analogRead(ustPin) >= 0) && ((analogRead(ustPin) < 50)))
- {
- tm.reset();
- tm.displayText(" 14.00");
- delay(100);
- }
- else if((analogRead(ustPin) >= 50) && ((analogRead(ustPin) < 100)))
- {
- tm.reset();
- tm.displayText(" 14.10");
- delay(100);
- }
- else if((analogRead(ustPin) >= 100) && ((analogRead(ustPin) < 150)))
- {
- tm.reset();
- tm.displayText(" 14.20");
- delay(100);
- }
- else if((analogRead(ustPin) >= 150) && ((analogRead(ustPin) < 200)))
- {
- tm.reset();
- tm.displayText(" 14.30");
- delay(100);
- }
- else if((analogRead(ustPin) >= 200) && ((analogRead(ustPin) < 250)))
- {
- tm.reset();
- tm.displayText(" 14.40");
- delay(100);
- }
- else if((analogRead(ustPin) >= 250) && ((analogRead(ustPin) < 300)))
- {
- tm.reset();
- tm.displayText(" 14.50");
- delay(100);
- }
- else if((analogRead(ustPin) >= 300) && ((analogRead(ustPin) < 350)))
- {
- tm.reset();
- tm.displayText(" 14.60");
- delay(100);
- }
- else if((analogRead(ustPin) >= 350) && ((analogRead(ustPin) < 400)))
- {
- tm.reset();
- tm.displayText(" 14.70");
- delay(100);
- }
- else if((analogRead(ustPin) >= 400) && ((analogRead(ustPin) < 450)))
- {
- tm.reset();
- tm.displayText(" 14.80");
- delay(100);
- }
- else if((analogRead(ustPin) >= 450) && ((analogRead(ustPin) < 500)))
- {
- tm.reset();
- tm.displayText(" 14.90");
- delay(100);
- }
- else if((analogRead(ustPin) >= 500) && ((analogRead(ustPin) < 550)))
- {
- tm.reset();
- tm.displayText(" 15.00");
- delay(100);
- }
- else if((analogRead(ustPin) >= 550) && ((analogRead(ustPin) < 600)))
- {
- tm.reset();
- tm.displayText(" 15.10");
- delay(100);
- }
- else if((analogRead(ustPin) >= 600) && ((analogRead(ustPin) < 650)))
- {
- tm.reset();
- tm.displayText(" 15.20");
- delay(100);
- }
- else if((analogRead(ustPin) >= 650) && ((analogRead(ustPin) < 700)))
- {
- tm.reset();
- tm.displayText(" 15.30");
- delay(100);
- }
- else if((analogRead(ustPin) >= 700) && ((analogRead(ustPin) < 750)))
- {
- tm.reset();
- tm.displayText(" 15.40");
- delay(100);
- }
- else if((analogRead(ustPin) >= 750) && ((analogRead(ustPin) < 800)))
- {
- tm.reset();
- tm.displayText(" 15.50");
- delay(100);
- }
- else if((analogRead(ustPin) >= 800) && ((analogRead(ustPin) < 850)))
- {
- tm.reset();
- tm.displayText(" 15.60");
- delay(100);
- }
- else if((analogRead(ustPin) >= 850) && ((analogRead(ustPin) < 900)))
- {
- tm.reset();
- tm.displayText(" 15.70");
- delay(100);
- }
- else if((analogRead(ustPin) >= 900) && ((analogRead(ustPin) < 950)))
- {
- tm.reset();
- tm.displayText(" 15.80");
- delay(100);
- }
- else if((analogRead(ustPin) >= 950) && ((analogRead(ustPin) < 1000)))
- {
- tm.reset();
- tm.displayText(" 15.90");
- delay(100);
- }
- else if(analogRead(ustPin) >= 1000)
- {
- tm.reset();
- tm.displayText(" 16.00");
- delay(100);
- }
- }
- else if(digitalRead(otwPin)==LOW)
- {
- tm.reset();
- tm.displayText("OTwArTE");
- Serial.println("otwarte");
- digitalWrite(prze, LOW);
- delay(5000);
- }
- else
- {
- if(ciezar <= ust*0.01)
- {
- digitalWrite(prze, HIGH);
- }
- else if(ciezar > ust*0.01)
- {
- digitalWrite(prze, LOW);
- delay(1000);
- }
- tm.displayText(odczyt);
- Serial.println(odczyt);
- Serial.println(ust);
- delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement