11 #include <Arduino_FreeRTOS.h>
12 #include <arduinoFFT.h>
20 #define SETLEDDDR LEDDDR |= BIT_2
21 #define SETLEDPORT LEDPORT |= BIT_2
22 #define CLEARLEDPORT LEDPORT &= !(BIT_2)
23 #define SETSPEAKERDDR SPEAKERDDR |= BIT_3
28 #define ROTARYPORT LEDPORT
39 #define SPEAKERDDR DDRH
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
68 #define TIMERCOMPARE4A OCR4A
69 #define TIMERCOMPARE3A OCR3A
70 #define TIMER3VAL TCNT3
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)
84 #define TIMER4REGA TCCR4A
85 #define TIMER4REGB TCCR4B
86 #define TIMER3REGA TCCR3A
87 #define TIMER3REGB TCCR3B
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
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
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
123 #define CLOCKFREQ 16000000
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
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
160 #define STATREGINTON STATREG |= BIT_7
161 #define STATREGINTOFF STATREG &= !BIT_7
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;
180 void RT1(
void *pvParameters );
181 void RT2(
void *pvParameters );
182 void RT3(
void *pvParameters );
183 void RT4(
void *pvParameters );
190 static QueueHandle_t Q_disp_value, pseudoArraySend, pseudoArrayDone, setLedDone;
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};
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} };
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
229 #define CLEARROW 0b00000000
230 #define ROUNDERR 0.47
235 arduinoFFT
FFT = arduinoFFT();
242 #define ULONG_MAX 0xFFFFFFFFUL
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;
320 #define NOTE_CS6 1109
322 #define NOTE_DS6 1245
325 #define NOTE_FS6 1480
327 #define NOTE_GS6 1661
329 #define NOTE_AS6 1865
332 #define NOTE_CS7 2217
334 #define NOTE_DS7 2489
337 #define NOTE_FS7 2960
339 #define NOTE_GS7 3322
341 #define NOTE_AS7 3729
344 #define NOTE_CS8 4435
346 #define NOTE_DS8 4978
430 18, 18, 18, 18, 18, 18,
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