-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlinkTime.c
111 lines (90 loc) · 1.96 KB
/
BlinkTime.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* BlinkTime
*
* A stopwatch utility to determine
* the time length of an operation
* in kilo_ticks.
*
* Note: Affected by endianness--check
* processor and adjust bit-shifts/reads
* accordingly.
*
* Outputs LSB binary number where
* YELLOW is "START/STOP",
* RED is 0,
* WHITE is 1.
*(Read left-to-right in time)
*
* @author Tom West
* @date 7/18/2022
* @version 1.0
*
*/
#include "kilolib.h"
#define MAX_COUNT 10000
enum {
ONE,
ZERO,
START,
STOP,
} TimeSyms;
//operations
int counter = 0;
//stopwatch
uint32_t t_initial = 0;
uint32_t t_final = 0;
uint32_t t_delta = 0;
//showTime:
int i;
int k;
int timeWordSize = 8; //assume 8-bit word
uint8_t binary_time = 0;
//Inspired by the bitwise decimal-to-binary
//converter from Geeks for Geeks found here:
// https://www.geeksforgeeks.org/program-decimal-binary-conversion/
void showTime(uint32_t time_in) {
set_color(RGB(0,3,0)); //Blink GREEN at beginning
delay(250);
set_color(RGB(0,0,0));
delay(250);
for (j = timeWordSize; j >= 0; j--) {
k = time_in >> j;
if (k & 1) {
set_color(RGB(3,3,3)); //flash WHITE for 1
delay(250);
set_color(RBB(0,0,0));
delay(250);
} else {
set_color(RGB(1,1,0)); //flash YELLOW for 0
delay(250);
set_color(RGB(0,0,0));
delay(250);
}//end if-else
}//end for
set_color(RGB(3,0,0)); //blink RED at end
delay(250);
set_color(RGB(0,0,0));
delay(250);
}//end showTime()
void setup(){
//initialize kilo_ticks at t_0
//(don't forget to zero-out assignment time :-)
t_initial = kilo_ticks;
}//end setup()
void loop(){
while (counter < MAX_COUNT) {
counter++; //do until max count reached
}//end for
//takes trivial time to compute... but, must be considered
//in more-precise applications!
t_final = kilo_ticks;
t_delta = t_final - t_initial;
while(1) {
showTime(t_delta); //output binary # representation
}//end while
}//end loop()
int main() {
kilo_init();
kilo_start(setup, loop);
}//end main()
//end program{}