My Project
lab4_define.h
Go to the documentation of this file.
1 
11 #include <Arduino_FreeRTOS.h>
12 #include <arduinoFFT.h>
13 #include <queue.h>
14 #include <stdio.h>
15 
18 #define LEDPORT PORTL
19 #define LEDDDR DDRL
20 #define SETLEDDDR LEDDDR |= BIT_2
21 #define SETLEDPORT LEDPORT |= BIT_2
22 #define CLEARLEDPORT LEDPORT &= !(BIT_2)
23 #define SETSPEAKERDDR SPEAKERDDR |= BIT_3
25 
28 #define ROTARYPORT LEDPORT
29 #define clkIN 52
30 #define dtIN 50
33 int carPosition = 3;
34 int lastRow = B00000000;
36 
37 
39 #define SPEAKERDDR DDRH
40 
43 #define BIT_0 1
44 #define BIT_1 1<<1
45 #define BIT_2 1<<2
46 #define BIT_3 1<<3
47 #define BIT_4 1<<4
48 #define BIT_5 1<<5
49 #define BIT_6 1<<6
50 #define BIT_7 1<<7
52 
54 #define TIMERPPR PRR1
55 
58 #define SEVENSEGPORT1 PORTA
59 #define SEVENSEGDDR1 DDRA
60 #define SEVENSEGPORT2 PORTC
61 #define SEVENSEGDDR2 DDRC
62 #define SETSEVSEGDDR1 SEVENSEGDDR1 |= BIT_7 | BIT_6 | BIT_5 | BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0
63 #define SETSEVSEGDDR2 SEVENSEGDDR2 |= BIT_7 | BIT_6 | BIT_5
65 
68 #define TIMERCOMPARE4A OCR4A
69 #define TIMERCOMPARE3A OCR3A
70 #define TIMER3VAL TCNT3
72 
75 #define TIMER4_ON_BIT 1<<PRTIM4
76 #define TIMER3_ON_BIT 1<<PRTIM3
77 #define TIMER4ON TIMERPPR &= !(TIMER4_ON_BIT)
78 #define TIMER3ON TIMERPPR &= !(TIMER3_ON_BIT)
79 #define TIMER3OFF TIMERPPR |= (TIMER3_ON_BIT)
81 
84 #define TIMER4REGA TCCR4A
85 #define TIMER4REGB TCCR4B
86 #define TIMER3REGA TCCR3A
87 #define TIMER3REGB TCCR3B
89 
90 
93 #define WGM4_BIT_0 1<<WGM40
94 #define WGM4_BIT_1 1<<WGM41
95 #define WGM4_BIT_2 1<<WGM42
96 #define WGM4_BIT_3 1<<WGM43
97 #define WGM3_BIT_0 1<<WGM30
98 #define WGM3_BIT_1 1<<WGM31
99 #define WGM3_BIT_2 1<<WGM32
100 #define WGM3_BIT_3 1<<WGM33
102 
105 #define PSCALE4_BIT_0 1<<CS40
106 #define PSCALE4_BIT_1 1<<CS41
107 #define PSCALE4_BIT_2 1<<CS42
108 #define PSCALE3_BIT_0 1<<CS30
109 #define PSCALE3_BIT_1 1<<CS31
110 #define PSCALE3_BIT_2 1<<CS32
112 
115 #define SETTIMER4REGA TIMER4REGA |= WGM4_BIT_0 | WGM4_BIT_1 | COMPARE_MODE4
116 #define SETTIMER4REGB TIMER4REGB |= WGM4_BIT_2 | WGM4_BIT_3 | PSCALE4_BIT_0
117 #define SETTIMER3REGA TIMER3REGA |= WGM3_BIT_0 | WGM3_BIT_1 | COMPARE_MODE3
118 #define SETTIMER3REGB TIMER3REGB |= WGM3_BIT_2 | WGM3_BIT_3 | PSCALE3_BIT_0
120 
123 #define CLOCKFREQ 16000000
124 #define TWO 2
125 #define THREE 3
126 #define TEN 10
127 #define HUNDRED 100
128 #define THOUSAND 1000
129 #define COMPARE_2000 16000
130 #define COMPARE_293 27304
131 #define COMPARE_329 24316
132 #define COMPARE_261 30651
133 #define COMPARE_130 61538
134 #define COMPARE_196 40816
135 #define COMPARE_NONE 0
136 #define COMPARE_1 62500
137 #define COMPARE_MODE4 1<<COM4A0
138 #define COMPARE_MODE3 1<<COM3A0
140 
143 #define SIXSECINMILLIS 6000
144 #define FOURSECINMILLIS 4000
145 #define THREESECINMILLIS 3000
146 #define TWOSECINMILLIS 2000
147 #define SECINMILLIS 1000
148 #define HALFSECINMILLIS 500
149 #define QUARSECINMILLIS 250
150 #define THREEQUARSECINMILLIS 750
152 
153 
155 int i, j, k;
156 
159 #define STATREG SREG
160 #define STATREGINTON STATREG |= BIT_7
161 #define STATREGINTOFF STATREG &= !BIT_7
163 
166 #define TIMER3INTREG TIMSK3
167 #define TIMER3INTBIT 1<<OCIE3A
168 #define TIMER3INTVEC TIMER3_COMPA_vect
169 #define TIMER3INTON TIMER3INTREG |= TIMER3INTBIT
170 #define TIMER3INTOFF TIMER3INTREG &= !TIMER3INTBIT
171 volatile static int isrcount=0;
173 
179 
180 void RT1( void *pvParameters );
181 void RT2( void *pvParameters );
182 void RT3( void *pvParameters );
183 void RT4( void *pvParameters );
184 void Task_Counter( void *pvParameters );
185 void useEncoderWithMatrix(void **pvParameters);
186 void readRotaryEncoder(void **pvParameters);
187 void setLed(void **pvParameters);
188 void crash(void **pvParameters);
189 
190 static QueueHandle_t Q_disp_value, pseudoArraySend, pseudoArrayDone, setLedDone;
192 
195 volatile byte segbits[7] = {7, 0, 5, 3, 1, 6, 7};
196 volatile uint8_t * segports[7] = {&PORTC, &PORTA, &PORTA, &PORTA, &PORTA, &PORTA, &PORTA};
197 volatile uint8_t * segddrs[7] = {&DDRC, &DDRA, &DDRA, &DDRA, &DDRA, &DDRA, &DDRA};
198 uint8_t digbits[4] = {5, 4, 2, 6};
199 volatile uint8_t * digports[4] = {&PORTC, &PORTA, &PORTA, &PORTC};
200 volatile uint8_t * digddrs[4] = {&DDRC, &DDRA, &DDRA, &DDRC};
201 volatile static int digsegs[11][8] = {
202 {1, 1, 1, 1, 1, 1, 0, 0},
203 {0, 1, 1, 0, 0, 0, 0, 0},
204 {1, 1, 0, 1, 1, 0, 1, 0},
205 {1, 1, 1, 1, 0, 0, 1, 0},
206 {0, 1, 1, 0, 0, 1, 1, 0},
207 {1, 0, 1, 1, 0, 1, 1, 0},
208 {1, 0, 1, 1, 1, 1, 1, 0},
209 {1, 1, 1, 0, 0, 0, 0, 0},
210 {1, 1, 1, 1, 1, 1, 1, 0},
211 {1, 1, 1, 1, 0, 1, 1, 0},
212 {0, 0, 0, 0, 0, 0, 0, 0} };
214 
217 byte spidata[16];
218 void spiTransfer(volatile byte row, volatile byte data);
219 #define OP_DECODEMODE 8
220 #define OP_SCANLIMIT 10
221 #define OP_SHUTDOWN 11
222 #define OP_DISPLAYTEST 14
223 #define OP_INTENSITY 10
224 #define DIN 42
225 #define CS 44
226 #define CLK 46
227 #define ROWS 8
228 #define COLS 8
229 #define CLEARROW 0b00000000
230 #define ROUNDERR 0.47
232 
235 arduinoFFT FFT = arduinoFFT(); /* Create FFT object */
236 const uint16_t samples = 256;
238 const double signalFrequency = 1000;
239 const double samplingFrequency = 5000;
240 double vReal[samples];
241 double vImag[samples];
242 #define ULONG_MAX 0xFFFFFFFFUL
244 
247 #define leds0 B11000011
249 uint8_t objects[9] = {B00000000, B10000000, B01000000, B00100000, B00010000,
250  B00001000, B00000100, B00000010, B00000001};
251 static int mycount=0;
252 static int bestcount = 0;
254 
258 #define NOTE_B0 31
259 #define NOTE_C1 33
260 #define NOTE_CS1 35
261 #define NOTE_D1 37
262 #define NOTE_DS1 39
263 #define NOTE_E1 41
264 #define NOTE_F1 44
265 #define NOTE_FS1 46
266 #define NOTE_G1 49
267 #define NOTE_GS1 52
268 #define NOTE_A1 55
269 #define NOTE_AS1 58
270 #define NOTE_B1 62
271 #define NOTE_C2 65
272 #define NOTE_CS2 69
273 #define NOTE_D2 73
274 #define NOTE_DS2 78
275 #define NOTE_E2 82
276 #define NOTE_F2 87
277 #define NOTE_FS2 93
278 #define NOTE_G2 98
279 #define NOTE_GS2 104
280 #define NOTE_A2 110
281 #define NOTE_AS2 117
282 #define NOTE_B2 123
283 #define NOTE_C3 131
284 #define NOTE_CS3 139
285 #define NOTE_D3 147
286 #define NOTE_DS3 156
287 #define NOTE_E3 165
288 #define NOTE_F3 175
289 #define NOTE_FS3 185
290 #define NOTE_G3 196
291 #define NOTE_GS3 208
292 #define NOTE_A3 220
293 #define NOTE_AS3 233
294 #define NOTE_B3 247
295 #define NOTE_C4 262
296 #define NOTE_CS4 277
297 #define NOTE_D4 294
298 #define NOTE_DS4 311
299 #define NOTE_E4 330
300 #define NOTE_F4 349
301 #define NOTE_FS4 370
302 #define NOTE_G4 392
303 #define NOTE_GS4 415
304 #define NOTE_A4 440
305 #define NOTE_AS4 466
306 #define NOTE_B4 494
307 #define NOTE_C5 523
308 #define NOTE_CS5 554
309 #define NOTE_D5 587
310 #define NOTE_DS5 622
311 #define NOTE_E5 659
312 #define NOTE_F5 698
313 #define NOTE_FS5 740
314 #define NOTE_G5 784
315 #define NOTE_GS5 831
316 #define NOTE_A5 880
317 #define NOTE_AS5 932
318 #define NOTE_B5 988
319 #define NOTE_C6 1047
320 #define NOTE_CS6 1109
321 #define NOTE_D6 1175
322 #define NOTE_DS6 1245
323 #define NOTE_E6 1319
324 #define NOTE_F6 1397
325 #define NOTE_FS6 1480
326 #define NOTE_G6 1568
327 #define NOTE_GS6 1661
328 #define NOTE_A6 1760
329 #define NOTE_AS6 1865
330 #define NOTE_B6 1976
331 #define NOTE_C7 2093
332 #define NOTE_CS7 2217
333 #define NOTE_D7 2349
334 #define NOTE_DS7 2489
335 #define NOTE_E7 2637
336 #define NOTE_F7 2794
337 #define NOTE_FS7 2960
338 #define NOTE_G7 3136
339 #define NOTE_GS7 3322
340 #define NOTE_A7 3520
341 #define NOTE_AS7 3729
342 #define NOTE_B7 3951
343 #define NOTE_C8 4186
344 #define NOTE_CS8 4435
345 #define NOTE_D8 4699
346 #define NOTE_DS8 4978
347 int melody[] = { 0, 0,
348  NOTE_E7, NOTE_E7, 0, NOTE_E7,
349  0, NOTE_C7, NOTE_E7, 0,
350  NOTE_G7, 0, 0, 0,
351  NOTE_G6, 0, 0, 0,
352  NOTE_C7, 0, 0, NOTE_G6,
353  0, 0, NOTE_E6, 0,
354  0, NOTE_A6, 0, NOTE_B6,
355  0, NOTE_AS6, NOTE_A6, 0,
357  NOTE_A7, 0, NOTE_F7, NOTE_G7,
358  0, NOTE_E7, 0, NOTE_C7,
359  NOTE_D7, NOTE_B6, 0, 0,
360  NOTE_C7, 0, 0, NOTE_G6,
361  0, 0, NOTE_E6, 0,
362  0, NOTE_A6, 0, NOTE_B6,
363  0, NOTE_AS6, NOTE_A6, 0,
365  NOTE_A7, 0, NOTE_F7, NOTE_G7,
366  0, NOTE_E7, 0, NOTE_C7,
367  NOTE_D7, NOTE_B6, 0, 0
368 };
369 int tempo[] = { 12, 12,
370  12, 12, 12, 12,
371  12, 12, 12, 12,
372  12, 12, 12, 12,
373  12, 12, 12, 12,
374  12, 12, 12, 12,
375  12, 12, 12, 12,
376  12, 12, 12, 12,
377  12, 12, 12, 12,
378  9, 9, 9,
379  12, 12, 12, 12,
380  12, 12, 12, 12,
381  12, 12, 12, 12,
382  12, 12, 12, 12,
383  12, 12, 12, 12,
384  12, 12, 12, 12,
385  12, 12, 12, 12,
386  9, 9, 9,
387  12, 12, 12, 12,
388  12, 12, 12, 12,
389  12, 12, 12, 12,
390 };
391 
394  NOTE_AS3, NOTE_AS4, 0,
395  0,
397  NOTE_AS3, NOTE_AS4, 0,
398  0,
400  NOTE_DS3, NOTE_DS4, 0,
401  0,
403  NOTE_DS3, NOTE_DS4, 0,
407  NOTE_G3, NOTE_CS4,
411  0, 0, 0
412 };
413 
415  12, 12, 12, 12,
416  12, 12, 6,
417  3,
418  12, 12, 12, 12,
419  12, 12, 6,
420  3,
421  12, 12, 12, 12,
422  12, 12, 6,
423  3,
424  12, 12, 12, 12,
425  12, 12, 6,
426  6, 18, 18, 18,
427  6, 6,
428  6, 6,
429  6, 6,
430  18, 18, 18, 18, 18, 18,
431  10, 10, 10,
432  10, 10, 10,
433  3, 3, 3
434 };
435 int thisNote= 0;
436 int thisNoteEnd = 0;
arduinoFFT FFT
Definition: lab4_define.h:235
TaskHandle_t playMusicEndhandle
Definition: lab4_define.h:178
TaskHandle_t RT3handle
Definition: lab4_define.h:176
volatile uint8_t * segddrs[7]
Definition: lab4_define.h:197
void RT4(void *pvParameters)
Definition: lab4.ino:183
#define NOTE_DS3
Definition: lab4_define.h:286
#define NOTE_F3
Definition: lab4_define.h:288
uint8_t objects[9]
Definition: lab4_define.h:249
void RT1(void *pvParameters)
Definition: lab4.ino:83
#define NOTE_E3
Definition: lab4_define.h:287
#define NOTE_AS3
Definition: lab4_define.h:293
volatile uint8_t * digddrs[4]
Definition: lab4_define.h:200
int j
Definition: lab4_define.h:155
#define NOTE_A6
Definition: lab4_define.h:328
#define NOTE_FS4
Definition: lab4_define.h:301
int thisNoteEnd
Definition: lab4_define.h:436
TaskHandle_t readRotaryEncoderhandle
Definition: lab4_define.h:177
#define leds0
Definition: lab4_define.h:247
#define NOTE_C7
Definition: lab4_define.h:331
TaskHandle_t setLedshandle
Definition: lab4_define.h:177
#define NOTE_A4
Definition: lab4_define.h:304
uint8_t digbits[4]
Definition: lab4_define.h:198
int melody[]
Definition: lab4_define.h:347
TaskHandle_t setLedhandle
Definition: lab4_define.h:177
void RT2(void *pvParameters)
Definition: lab4.ino:108
#define NOTE_G3
Definition: lab4_define.h:290
#define NOTE_D4
Definition: lab4_define.h:297
TaskHandle_t readButtonshandle
Definition: lab4_define.h:178
const double samplingFrequency
Definition: lab4_define.h:239
#define NOTE_DS4
Definition: lab4_define.h:298
int currentStateClk
Definition: lab4_define.h:31
TaskHandle_t playMusichandle
Definition: lab4_define.h:177
int tempo[]
Definition: lab4_define.h:369
void useEncoderWithMatrix(void **pvParameters)
int previousStateClk
Definition: lab4_define.h:32
TaskHandle_t RTtaskshandle
Definition: lab4_define.h:178
const double signalFrequency
Definition: lab4_define.h:238
int underworld_tempo[]
Definition: lab4_define.h:414
int leds[8]
Definition: lab4_define.h:248
#define NOTE_E6
Definition: lab4_define.h:323
int thisNote
Definition: lab4_define.h:435
#define NOTE_C5
Definition: lab4_define.h:307
int underworld_melody[]
Definition: lab4_define.h:392
#define NOTE_A7
Definition: lab4_define.h:340
#define NOTE_B6
Definition: lab4_define.h:330
#define NOTE_A3
Definition: lab4_define.h:292
#define NOTE_E7
Definition: lab4_define.h:335
int carPosition
Definition: lab4_define.h:33
byte spidata[16]
Definition: lab4_define.h:217
#define NOTE_F7
Definition: lab4_define.h:336
#define NOTE_D3
Definition: lab4_define.h:285
void setLed(void **pvParameters)
TaskHandle_t Task_Counterhandle
Definition: lab4_define.h:176
#define NOTE_B3
Definition: lab4_define.h:294
double vReal[samples]
Definition: lab4_define.h:240
#define NOTE_AS6
Definition: lab4_define.h:329
double vImag[samples]
Definition: lab4_define.h:241
#define NOTE_AS4
Definition: lab4_define.h:305
TaskHandle_t RT4handle
Definition: lab4_define.h:176
int k
Definition: lab4_define.h:155
#define NOTE_G6
Definition: lab4_define.h:326
TaskHandle_t RT2handle
Definition: lab4_define.h:176
void readRotaryEncoder(void **pvParameters)
#define NOTE_GS4
Definition: lab4_define.h:303
volatile uint8_t * segports[7]
Definition: lab4_define.h:196
TaskHandle_t restarthandle
Definition: lab4_define.h:178
const uint16_t samples
Definition: lab4_define.h:236
void RT3(void *pvParameters)
Definition: lab4.ino:141
int i
iterators
Definition: lab4_define.h:155
int lastRow
Definition: lab4_define.h:34
volatile uint8_t * digports[4]
Definition: lab4_define.h:199
void crash(void **pvParameters)
void Task_Counter(void *pvParameters)
Definition: lab4.ino:219
TaskHandle_t RT3p0handle
Definition: lab4_define.h:176
void spiTransfer(volatile byte row, volatile byte data)
Definition: lab4.ino:364
volatile byte segbits[7]
Definition: lab4_define.h:195
#define NOTE_C4
Definition: lab4_define.h:295
TaskHandle_t playDrivingGamehandle
Definition: lab4_define.h:177
#define NOTE_GS3
Definition: lab4_define.h:291
int pseudoArray[samples]
Definition: lab4_define.h:237
#define NOTE_CS4
Definition: lab4_define.h:296
#define NOTE_D7
Definition: lab4_define.h:333
TaskHandle_t RT3p1handle
Definition: lab4_define.h:176
#define NOTE_G7
Definition: lab4_define.h:338
TaskHandle_t RT1handle
Definition: lab4_define.h:176
#define NOTE_F4
Definition: lab4_define.h:300