arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

mittalaite_v3.ino (3594B)


      1 /*
      2   LiquidCrystal Library - Hello World
      3 
      4  Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
      5  library works with all LCD displays that are compatible with the
      6  Hitachi HD44780 driver. There are many of them out there, and you
      7  can usually tell them by the 16-pin interface.
      8 
      9  This sketch prints "Hello World!" to the LCD
     10  and shows the time.
     11 
     12   The circuit:
     13  * LCD RS pin to digital pin 12
     14  * LCD Enable pin to digital pin 11
     15  * LCD D4 pin to digital pin 5
     16  * LCD D5 pin to digital pin 4
     17  * LCD D6 pin to digital pin 3
     18  * LCD D7 pin to digital pin 2
     19  * LCD R/W pin to ground
     20  * LCD VSS pin to ground
     21  * LCD VCC pin to 5V
     22  * 10K resistor:
     23  * ends to +5V and ground
     24  * wiper to LCD VO pin (pin 3)
     25 
     26  Library originally added 18 Apr 2008
     27  by David A. Mellis
     28  library modified 5 Jul 2009
     29  by Limor Fried (http://www.ladyada.net)
     30  example added 9 Jul 2009
     31  by Tom Igoe
     32  modified 22 Nov 2010
     33  by Tom Igoe
     34  modified 7 Nov 2016
     35  by Arturo Guadalupi
     36 
     37  This example code is in the public domain.
     38 
     39  http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
     40 
     41 */
     42 
     43 // include the library code:
     44 #include <LiquidCrystal.h>
     45 
     46 // initialize the library by associating any needed LCD interface pin
     47 // with the arduino pin number it is connected to
     48 const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
     49 float langd = 300;
     50 float countcm = 0;
     51 int steps1 = 0;
     52 int steps2 = 0;
     53 int steps = 0;
     54 float calib = 2.00;
     55 int optsensor1;
     56 int optsensor2;
     57 unsigned long impulstid = 500;
     58 boolean counted = false;
     59 boolean countstep1 = false;
     60 boolean countstep2 = false;
     61 LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
     62 
     63 void setup() {
     64   // set up the LCD's number of columns and rows:
     65   lcd.begin(16, 2);
     66   pinMode(1, OUTPUT);
     67   pinMode(7, INPUT_PULLUP); //knapp 1
     68   pinMode(8, INPUT_PULLUP); //knapp 2
     69   pinMode(9, INPUT_PULLUP); //knapp 3  
     70   pinMode(10, INPUT_PULLUP); //knapp 4
     71   pinMode(6, INPUT); //optisksensor 1
     72   pinMode(13, INPUT); //optisksensor 2
     73   digitalWrite(1, HIGH); //relay
     74 }
     75 
     76 void loop() {
     77   if (millis() - impulstid == 500) {
     78     lcd.clear();
     79     // set the cursor to column 0, line 1
     80     // (note: line 1 is the second row, since counting begins with 0):
     81     lcd.setCursor(0, 0);
     82     lcd.print("s:" + String(steps) + " c:" + String(calib));
     83     lcd.setCursor(0, 1);
     84     lcd.print("L:" + String(int(langd)) + "/" + String(int(countcm)) + " cm" );
     85   }
     86   if (countcm >= (langd - 8)){
     87     digitalWrite(1, HIGH); //relay
     88   }
     89   else{
     90     digitalWrite(1, LOW); //relay
     91   }
     92   if (digitalRead(7) == LOW){
     93     langd = langd + 5;
     94     impulstid = millis();
     95     delay(300);
     96     lcd.clear();
     97   }
     98   if (digitalRead(8) == LOW){
     99     langd = langd - 5;
    100     impulstid = millis();
    101     delay(300);
    102     lcd.clear();
    103   }
    104   if (digitalRead(9) == LOW){
    105     countcm = 0;
    106     steps = 0;
    107     impulstid = millis();
    108     delay(100);
    109     lcd.clear();
    110   }
    111   if (digitalRead(13) == LOW){
    112     countstep1 = false;
    113   }
    114   if (digitalRead(13) == HIGH){
    115     countstep1 = true;
    116     }
    117   if (digitalRead(6) == LOW){
    118     countstep2 = false;
    119     }
    120   if (digitalRead(6) == HIGH){
    121     countstep2 = true;
    122     }
    123   if (countstep1 == true){
    124     if (countstep2 == false){
    125       if (counted == false){
    126         countcm = countcm + calib;
    127         steps = steps + 1;
    128         impulstid = millis();
    129         counted = true;
    130         }
    131       }
    132     }
    133   if (countstep1 == false){
    134     if (countstep2 == true){
    135       if (counted == false){
    136         countcm = countcm - calib;
    137         steps = steps - 1;
    138         impulstid = millis();
    139         counted = true;
    140       }
    141     }
    142   }
    143   if (countstep1 == true){
    144     if (countstep2 == true){
    145       counted = false;
    146     }
    147   }
    148 }
    149 
    150