-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
42 lines (35 loc) · 1.21 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <wiringPi.h> //this library SHOULD be pre-installed with
//with standard Rasbian system.
//If it seems missing on your Raspberry, then
//I recommend following the steps provided here:
//http://wiringpi.com/download-and-install/
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define LED 17 //that means, that program will work with GPIO 17, which
//is number 11 on rpi GPIO pinout.
#define RAND_MAX 1000 //it's a max value that rand function can return
int main(void)
{
wiringPiSetupSys();
srand(time(0));
pinMode(LED, OUTPUT);
int count = 0; //counter
int rand_H; //the highest random value
int rand_L; //the lowest random value
const int iter = 10; //number of iterations
while (count < iter)
{
rand_H = rand() % RAND_MAX + 5;
digitalWrite(LED, HIGH);
delay(rand_H);
printf("Delay (HIGH): %d ms.\n", rand_H);
rand_L = rand() % RAND_MAX + 100;
digitalWrite(LED, LOW);
delay(rand_L);
printf("Delay (LOW): %d ms.\n", rand_L);
printf("Iteration: %d.\n", count);
count++;
}
return 0;
}