rastabrew

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

givarna.c (978B)


      1 #include <stdio.h>
      2 #include <wiringPi.h>
      3 #include <stdbool.h>
      4 #include <time.h>
      5 #include <unistd.h>
      6 
      7 int main(void)
      8 {
      9     // Switch: Physical pin 31, BCM GPIO6, and WiringPi pin 22.
     10     const int givare = 4;
     11     bool counted = false;
     12     long brew = 0;
     13     long brewold = 0;
     14     int timesleep = 5000;
     15 
     16     wiringPiSetup();
     17 
     18     pinMode(givare, INPUT);
     19     pullUpDnControl(givare, PUD_DOWN);
     20 
     21     while (1) {
     22         if ((digitalRead(givare) == HIGH)) {
     23             counted = true;
     24             usleep(1);
     25         }
     26         else {
     27             if (counted == true) {
     28                 brew = brew + 1;
     29                 counted = false;
     30             usleep(1);
     31         }
     32         }
     33         if (brewold != brew) {
     34             FILE * givarna;
     35             //printf("%ld", brew);
     36             givarna = fopen("/dev/shm/brew2","w+");
     37             fprintf(givarna, "%ld", brew);
     38             fclose(givarna);
     39             brewold = brew;
     40         }
     41         usleep(timesleep);
     42     }
     43     return 0;
     44 }