commit 48062d9d91a54f0dc94e35ac6b36d24fd10961a1
Author: Robin <rob@tarina.org>
Date: Wed, 7 Sep 2022 16:32:11 +0300
first
Diffstat:
2 files changed, 322 insertions(+), 0 deletions(-)
diff --git a/mittalaite_v3/mittalaite_v3.ino b/mittalaite_v3/mittalaite_v3.ino
@@ -0,0 +1,162 @@
+
+
+/*
+ Hansson Service
+ Mittalaite v.4
+*/
+
+// include the library code:
+#include <LiquidCrystal.h>
+#include <Keypad.h>
+
+// initialize keypad
+String newlenght = "";
+const byte ROWS = 4; //four rows
+const byte COLS = 3; //three columns
+char keys[ROWS][COLS] = {
+ {'1','2','3'},
+ {'4','5','6'},
+ {'7','8','9'},
+ {'*','0','#'}
+};
+byte rowPins[ROWS] = {A3, A2, A1, A0}; //connect to the row pinouts of the keypad
+byte colPins[COLS] = {8, A5, A4}; //connect to the column pinouts of the keypad
+Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
+
+// initialize the library by associating any needed LCD interface pin
+// with the arduino pin number it is connected to
+const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
+float langd = 300;
+float total_langd = 0;
+float countcm = 0;
+int steps1 = 0;
+int steps2 = 0;
+int steps = 0;
+float calib = 2.00;
+int optsensor1;
+int optsensor2;
+unsigned long impulstid = 0;
+unsigned long lcdrefresh = 0;
+boolean counted = false;
+boolean countstep1 = false;
+boolean countstep2 = false;
+LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
+
+void setup() {
+ // set up the LCD's number of columns and rows:
+ lcd.begin(16, 2);
+ pinMode(1, OUTPUT);
+ pinMode(7, INPUT_PULLUP); //knapp 1
+ pinMode(9, INPUT_PULLUP); //knapp 3
+ pinMode(10, INPUT_PULLUP); //knapp 4
+ pinMode(6, INPUT); //optisksensor 1
+ pinMode(13, INPUT); //optisksensor 2
+ digitalWrite(1, HIGH); //relay
+ }
+
+void loop() {
+ if ((millis() - impulstid >= 1500)) {
+ // set the cursor to column 0, line 1
+ // (note: line 1 is the second row, since counting begins with 0):
+ if (millis() - lcdrefresh > 50) {
+ if (newlenght == ""){
+ lcdrefresh = millis();
+ lcd.clear();
+ lcd.setCursor(0, 0);
+ lcd.print("L:" + String(int(langd)) + "/" + String(int(countcm)) + " cm");
+ lcd.setCursor(0, 1);
+ lcd.print("T:" + String(int(total_langd)) + String(int(countcm)) + " cm");
+ delay(200);
+ }
+ else{
+ lcd.clear();
+ lcd.setCursor(0, 0);
+ lcd.print("New lenght:");
+ lcd.setCursor(0, 1);
+ lcd.print(String(newlenght));
+ delay(200);
+ }
+ }
+ char key = keypad.getKey();
+ if (key){
+ newlenght += key;
+ }
+ if (key == '#'){
+ if (newlenght != ""){
+ langd = newlenght.toInt();
+ newlenght = "";
+ }
+ else{
+ newlenght = "";
+ }
+ }
+ if (key == '*'){
+ newlenght = "";
+ }
+ }
+ if (countcm >= (langd - 13)){
+ digitalWrite(1, HIGH); //relay
+ }
+ else{
+ digitalWrite(1, LOW); //relay
+ }
+ if (digitalRead(7) == LOW){
+ langd = langd + 5;
+ impulstid = millis();
+ delay(300);
+ lcd.clear();
+ }
+ if (digitalRead(8) == LOW){
+ langd = langd - 5;
+ impulstid = millis();
+ delay(300);
+ lcd.clear();
+ }
+ if (digitalRead(9) == LOW){
+ total_langd += countcm;
+ countcm = 0;
+ steps = 0;
+ impulstid = millis();
+ delay(100);
+ lcd.clear();
+ }
+ if (digitalRead(13) == LOW){
+ countstep1 = false;
+ }
+ if (digitalRead(13) == HIGH){
+ countstep1 = true;
+ }
+ if (digitalRead(6) == LOW){
+ countstep2 = false;
+ }
+ if (digitalRead(6) == HIGH){
+ countstep2 = true;
+ }
+ if (countstep1 == true){
+ if (countstep2 == false){
+ if (counted == false){
+ countcm = countcm + calib;
+ steps = steps + 1;
+ impulstid = millis();
+ counted = true;
+ }
+ }
+ }
+ if (countstep1 == false){
+ if (countstep2 == true){
+ if (counted == false){
+ countcm = countcm - calib;
+ steps = steps - 1;
+ impulstid = millis();
+ counted = true;
+ }
+ }
+ }
+ if (countstep1 == true){
+ if (countstep2 == true){
+ counted = false;
+ }
+ }
+}
+
+
diff --git a/mittalaite_v4/mittalaite_v4.ino b/mittalaite_v4/mittalaite_v4.ino
@@ -0,0 +1,160 @@
+
+
+/*
+ Hansson Service
+ Mittalaite v.4
+*/
+
+// include the library code:
+#include <LiquidCrystal.h>
+#include <Keypad.h>
+
+// initialize keypad
+String newlenght = "";
+const byte ROWS = 4; //four rows
+const byte COLS = 3; //three columns
+char keys[ROWS][COLS] = {
+ {'1','2','3'},
+ {'4','5','6'},
+ {'7','8','9'},
+ {'*','0','#'}
+};
+byte rowPins[ROWS] = {A3, A2, A1, A0}; //connect to the row pinouts of the keypad
+byte colPins[COLS] = {8, A5, A4}; //connect to the column pinouts of the keypad
+Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
+
+// initialize the library by associating any needed LCD interface pin
+// with the arduino pin number it is connected to
+const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
+float langd = 300;
+float total_langd = 0;
+float countcm = 0;
+int steps1 = 0;
+int steps2 = 0;
+int steps = 0;
+float calib = 2.00;
+int optsensor1;
+int optsensor2;
+unsigned long impulstid = millis();
+unsigned long lcdrefresh = millis();
+boolean counted = false;
+boolean countstep1 = false;
+boolean countstep2 = false;
+LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
+
+void setup() {
+ // set up the LCD's number of columns and rows:
+ lcd.begin(16, 2);
+ pinMode(1, OUTPUT);
+ pinMode(7, INPUT_PULLUP); //knapp 1
+ pinMode(9, INPUT_PULLUP); //knapp 3
+ pinMode(10, INPUT_PULLUP); //knapp 4
+ pinMode(6, INPUT); //optisksensor 1
+ pinMode(13, INPUT); //optisksensor 2
+ digitalWrite(1, HIGH); //relay
+ }
+
+void loop() {
+ if ((millis() - impulstid > 1500)) {
+ // set the cursor to column 0, line 1
+ // (note: line 1 is the second row, since counting begins with 0):
+ if (millis() - lcdrefresh > 500) {
+ lcdrefresh = millis();
+ if (newlenght == ""){
+ lcd.clear();
+ lcd.setCursor(0, 0);
+ lcd.print("L:" + String(int(countcm)) + "/" + String(int(langd)) + " cm");
+ lcd.setCursor(0, 1);
+ lcd.print("T:" + String(int(total_langd)) + " cm");
+ }
+ else{
+ lcd.clear();
+ lcd.setCursor(0, 0);
+ lcd.print("New lenght:");
+ lcd.setCursor(0, 1);
+ lcd.print(String(newlenght));
+ }
+ }
+ char key = keypad.getKey();
+ if (key){
+ newlenght += key;
+ }
+ if (key == '#'){
+ if (newlenght != ""){
+ langd = newlenght.toInt();
+ newlenght = "";
+ }
+ else{
+ newlenght = "";
+ }
+ }
+ if (key == '*'){
+ newlenght = "";
+ }
+ }
+ if (countcm >= (langd - 13)){
+ digitalWrite(1, HIGH); //relay
+ }
+ else{
+ digitalWrite(1, LOW); //relay
+ }
+ if (digitalRead(7) == LOW){
+ if (millis() - impulstid < 10000){
+ total_langd += countcm;
+ }
+ countcm = 0;
+ steps = 0;
+ impulstid = millis();
+ delay(100);
+ lcd.clear();
+ }
+ if (digitalRead(9) == LOW){
+ if (millis() - impulstid < 10000){
+ total_langd += countcm;
+ }
+ countcm = 0;
+ steps = 0;
+ impulstid = millis();
+ delay(100);
+ lcd.clear();
+ }
+ if (digitalRead(13) == LOW){
+ countstep1 = false;
+ }
+ if (digitalRead(13) == HIGH){
+ countstep1 = true;
+ }
+ if (digitalRead(6) == LOW){
+ countstep2 = false;
+ }
+ if (digitalRead(6) == HIGH){
+ countstep2 = true;
+ }
+ if (countstep1 == true){
+ if (countstep2 == false){
+ if (counted == false){
+ countcm = countcm + calib;
+ steps = steps + 1;
+ impulstid = millis();
+ counted = true;
+ }
+ }
+ }
+ if (countstep1 == false){
+ if (countstep2 == true){
+ if (counted == false){
+ countcm = countcm - calib;
+ steps = steps - 1;
+ impulstid = millis();
+ counted = true;
+ }
+ }
+ }
+ if (countstep1 == true){
+ if (countstep2 == true){
+ counted = false;
+ }
+ }
+}
+
+