Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /*
- char readBtn1() {
- }*/
- int main ()
- {
- int rval;
- FILE *fp;
- FILE *fp1;
- FILE *fp2;
- char *str;
- int tval1,tval2;
- int tval1_old, tval2_old;
- size_t num_of_bytes = 1;
- float percentage;
- float pcnt_step = 0.2;
- long int period = 20000L;
- while(1)
- {
- //Citanje vrednosti prvog tastera
- fp1 = fopen ("/sys/class/gpio/gpio956/value", "r");
- if(fp1==NULL)
- puts("Problem pri otvaranju 1. fajla");
- str = (char *)malloc(num_of_bytes+1);
- getline(&str, &num_of_bytes, fp1);
- if(fclose(fp1))
- puts("Problem pri zatvaranju 1. fajla");
- sscanf(str, "%d", &tval1);
- free(str);
- if(tval1 && tval1 != tval1_old && percentage+pcnt_step < 1) {
- percentage+=pcnt_step;
- tval1_old = tval1;
- }
- // -----------------------------------------------
- //Citanje vrednosti drugog tastera
- fp2 = fopen ("/sys/class/gpio/gpio957/value", "r");
- if(fp2==NULL)
- puts("Problem pri otvaranju 2. fajla");
- str = (char *)malloc(num_of_bytes+1);
- getline(&str, &num_of_bytes, fp2);
- if(fclose(fp2))
- puts("Problem pri zatvaranju 2. fajla");
- sscanf(str, "%d", &tval2);
- free(str);
- //Ispis procitanih vrednosti
- printf("\n:Taster1: %d Taster2: %d", tval1, tval2);
- usleep(100000);
- if(tval2 && tval2 != tval2_old && percentage-pcnt_step > 0) {
- percentage-=pcnt_step;
- tval2_old = tval2;
- }
- // ------------------------------------------------
- fp = fopen("/proc/myled", "w");
- if(fp == NULL)
- {
- printf("Cannot open /proc/myled for write\n");
- return -1;
- }
- fputs("0x0F\n", fp);
- fclose(fp);
- usleep(percentage*period);
- fp = fopen("/proc/myled", "w");
- if(fp == NULL)
- {
- printf("Cannot open /proc/myled for write\n");
- return -1;
- }
- fputs("0x00\n", fp);
- fclose(fp);
- usleep((1-percentage)*period);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement