Template for the ELEC1620 End of year exam

Dependencies:   mbed

Committer:
el16ttb
Date:
Fri Mar 22 13:11:07 2019 +0000
Revision:
0:54721f063ac8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el16ttb 0:54721f063ac8 1 #include <mbed.h>
el16ttb 0:54721f063ac8 2
el16ttb 0:54721f063ac8 3 #include "ShiftReg.h"
el16ttb 0:54721f063ac8 4 #include "N5110.h"
el16ttb 0:54721f063ac8 5
el16ttb 0:54721f063ac8 6 #include "StreamOut.h"
el16ttb 0:54721f063ac8 7
el16ttb 0:54721f063ac8 8 #include "exam.h"
el16ttb 0:54721f063ac8 9
el16ttb 0:54721f063ac8 10 // #define IGNORE_SETUP
el16ttb 0:54721f063ac8 11
el16ttb 0:54721f063ac8 12
el16ttb 0:54721f063ac8 13 AnalogIn ldr(p15);
el16ttb 0:54721f063ac8 14
el16ttb 0:54721f063ac8 15 AnalogIn tmp36(p16);
el16ttb 0:54721f063ac8 16
el16ttb 0:54721f063ac8 17 AnalogIn pot_0(p20);
el16ttb 0:54721f063ac8 18 AnalogIn pot_1(p19);
el16ttb 0:54721f063ac8 19 AnalogIn pot_2(p17);
el16ttb 0:54721f063ac8 20
el16ttb 0:54721f063ac8 21 PwmOut r_led(p24);
el16ttb 0:54721f063ac8 22 PwmOut g_led(p23);
el16ttb 0:54721f063ac8 23 PwmOut b_led(p22);
el16ttb 0:54721f063ac8 24
el16ttb 0:54721f063ac8 25 DigitalIn button_a(p29);
el16ttb 0:54721f063ac8 26 DigitalIn button_b(p28);
el16ttb 0:54721f063ac8 27 DigitalIn button_c(p27);
el16ttb 0:54721f063ac8 28 DigitalIn button_d(p26);
el16ttb 0:54721f063ac8 29
el16ttb 0:54721f063ac8 30 N5110 lcd(p8,p9,p10,p11,p13,p21);
el16ttb 0:54721f063ac8 31
el16ttb 0:54721f063ac8 32 BusOut leds(LED4,LED3,LED2,LED1);
el16ttb 0:54721f063ac8 33
el16ttb 0:54721f063ac8 34 ShiftReg shift;
el16ttb 0:54721f063ac8 35
el16ttb 0:54721f063ac8 36 StreamOut streamOut;
el16ttb 0:54721f063ac8 37
el16ttb 0:54721f063ac8 38 TestAdmin testAdmin;
el16ttb 0:54721f063ac8 39
el16ttb 0:54721f063ac8 40 void init(){
el16ttb 0:54721f063ac8 41 //streamOut.lock();
el16ttb 0:54721f063ac8 42 lcd.init();
el16ttb 0:54721f063ac8 43 r_led.period_ms(10);
el16ttb 0:54721f063ac8 44 g_led.period_ms(10);
el16ttb 0:54721f063ac8 45 b_led.period_ms(10);
el16ttb 0:54721f063ac8 46 //streamOut.unlock();
el16ttb 0:54721f063ac8 47 }
el16ttb 0:54721f063ac8 48
el16ttb 0:54721f063ac8 49 void reset(){
el16ttb 0:54721f063ac8 50 r_led = 1;
el16ttb 0:54721f063ac8 51 g_led = 1;
el16ttb 0:54721f063ac8 52 b_led = 1;
el16ttb 0:54721f063ac8 53 shift.write(0x00);
el16ttb 0:54721f063ac8 54 // streamOut.lock();
el16ttb 0:54721f063ac8 55 lcd.clear();
el16ttb 0:54721f063ac8 56 lcd.refresh();
el16ttb 0:54721f063ac8 57 // streamOut.unlock();
el16ttb 0:54721f063ac8 58 leds = 0x0;
el16ttb 0:54721f063ac8 59 }
el16ttb 0:54721f063ac8 60
el16ttb 0:54721f063ac8 61 void waitRelease(){
el16ttb 0:54721f063ac8 62 streamOut.writeMessage(0xf, 0xFD);
el16ttb 0:54721f063ac8 63 streamOut.sendMessages();
el16ttb 0:54721f063ac8 64 streamOut.lock();
el16ttb 0:54721f063ac8 65 while(!testAdmin.testRunning()){
el16ttb 0:54721f063ac8 66 }
el16ttb 0:54721f063ac8 67 // lcd.clear();
el16ttb 0:54721f063ac8 68 // lcd.refresh();
el16ttb 0:54721f063ac8 69 streamOut.unlock();
el16ttb 0:54721f063ac8 70 }
el16ttb 0:54721f063ac8 71
el16ttb 0:54721f063ac8 72 int main() {
el16ttb 0:54721f063ac8 73 printf("Start\n");
el16ttb 0:54721f063ac8 74 streamOut.unlock();
el16ttb 0:54721f063ac8 75 streamOut.writeMessage(0xf, 0x0);
el16ttb 0:54721f063ac8 76 streamOut.sendMessages();
el16ttb 0:54721f063ac8 77
el16ttb 0:54721f063ac8 78 init();
el16ttb 0:54721f063ac8 79 reset();
el16ttb 0:54721f063ac8 80 lcd.setBrightness(1.0f);
el16ttb 0:54721f063ac8 81
el16ttb 0:54721f063ac8 82 #ifndef IGNORE_SETUP
el16ttb 0:54721f063ac8 83
el16ttb 0:54721f063ac8 84 while(testAdmin.testRunning()){
el16ttb 0:54721f063ac8 85 // streamOut.lock();
el16ttb 0:54721f063ac8 86 lcd.clear();
el16ttb 0:54721f063ac8 87 lcd.printString(" Adjust the", 0, 0);
el16ttb 0:54721f063ac8 88 lcd.printString("contrast with", 3, 1);
el16ttb 0:54721f063ac8 89 lcd.printString(" Pot 2", 0, 2);
el16ttb 0:54721f063ac8 90 lcd.printString("Cycle between", 3, 3);
el16ttb 0:54721f063ac8 91 lcd.printString(" tasks by", 0, 4);
el16ttb 0:54721f063ac8 92 lcd.printString(" pressing D", 0, 5);
el16ttb 0:54721f063ac8 93 lcd.setContrast(0.5 + (pot_2 - 0.5) * 0.4);
el16ttb 0:54721f063ac8 94 lcd.refresh();
el16ttb 0:54721f063ac8 95 // while(!button_a){}
el16ttb 0:54721f063ac8 96 // while(button_a){}
el16ttb 0:54721f063ac8 97
el16ttb 0:54721f063ac8 98 // streamOut.unlock();
el16ttb 0:54721f063ac8 99 }
el16ttb 0:54721f063ac8 100 reset();
el16ttb 0:54721f063ac8 101 #endif
el16ttb 0:54721f063ac8 102 testAdmin.printEnabled = true;
el16ttb 0:54721f063ac8 103 while(1){
el16ttb 0:54721f063ac8 104 #ifndef IGNORE_TASK_1
el16ttb 0:54721f063ac8 105 printf("Task 1\n");
el16ttb 0:54721f063ac8 106 testAdmin.setTaskName("Task 1", &lcd, &streamOut);
el16ttb 0:54721f063ac8 107 waitRelease();
el16ttb 0:54721f063ac8 108 streamOut.writeMessage(0xf, 0x1);
el16ttb 0:54721f063ac8 109 streamOut.sendMessages();
el16ttb 0:54721f063ac8 110 Task1(testAdmin, r_led, button_a);
el16ttb 0:54721f063ac8 111 reset();
el16ttb 0:54721f063ac8 112 #endif
el16ttb 0:54721f063ac8 113 #ifndef IGNORE_TASK_2
el16ttb 0:54721f063ac8 114 printf("Task 2\n");
el16ttb 0:54721f063ac8 115 testAdmin.setTaskName("Task 2", &lcd, &streamOut);
el16ttb 0:54721f063ac8 116 waitRelease();
el16ttb 0:54721f063ac8 117 streamOut.writeMessage(0xf, 0x2);
el16ttb 0:54721f063ac8 118 streamOut.sendMessages();
el16ttb 0:54721f063ac8 119 Task2(testAdmin, r_led, g_led, b_led, button_a, button_b, button_c);
el16ttb 0:54721f063ac8 120 reset();
el16ttb 0:54721f063ac8 121 #endif
el16ttb 0:54721f063ac8 122 #ifndef IGNORE_TASK_3
el16ttb 0:54721f063ac8 123 printf("Task 3\n");
el16ttb 0:54721f063ac8 124 testAdmin.setTaskName("Task 3", &lcd, &streamOut);
el16ttb 0:54721f063ac8 125 waitRelease();
el16ttb 0:54721f063ac8 126 streamOut.writeMessage(0xf, 0x3);
el16ttb 0:54721f063ac8 127 streamOut.sendMessages();
el16ttb 0:54721f063ac8 128 Task3(testAdmin, b_led, button_a, button_b);
el16ttb 0:54721f063ac8 129 reset();
el16ttb 0:54721f063ac8 130 #endif
el16ttb 0:54721f063ac8 131 #ifndef IGNORE_TASK_4
el16ttb 0:54721f063ac8 132 printf("Task 4\n");
el16ttb 0:54721f063ac8 133 testAdmin.setTaskName("Task 4", &lcd, &streamOut);
el16ttb 0:54721f063ac8 134 waitRelease();
el16ttb 0:54721f063ac8 135 streamOut.writeMessage(0xf, 0x4);
el16ttb 0:54721f063ac8 136 streamOut.sendMessages();
el16ttb 0:54721f063ac8 137 Task4(testAdmin, tmp36);
el16ttb 0:54721f063ac8 138 reset();
el16ttb 0:54721f063ac8 139 #endif
el16ttb 0:54721f063ac8 140 #ifndef IGNORE_TASK_5
el16ttb 0:54721f063ac8 141 printf("Task 5\n");
el16ttb 0:54721f063ac8 142 testAdmin.setTaskName("Task 5", &lcd, &streamOut);
el16ttb 0:54721f063ac8 143 waitRelease();
el16ttb 0:54721f063ac8 144 streamOut.writeMessage(0xf, 0x5);
el16ttb 0:54721f063ac8 145 streamOut.sendMessages();
el16ttb 0:54721f063ac8 146 Task5(testAdmin, r_led, g_led, ldr);
el16ttb 0:54721f063ac8 147 reset();
el16ttb 0:54721f063ac8 148 #endif
el16ttb 0:54721f063ac8 149 #ifndef IGNORE_TASK_6
el16ttb 0:54721f063ac8 150 printf("Task 6\n");
el16ttb 0:54721f063ac8 151 testAdmin.setTaskName("Task 6", &lcd, &streamOut);
el16ttb 0:54721f063ac8 152 waitRelease();
el16ttb 0:54721f063ac8 153 streamOut.writeMessage(0xf, 0x6);
el16ttb 0:54721f063ac8 154 streamOut.sendMessages();
el16ttb 0:54721f063ac8 155 Task6(testAdmin, r_led, g_led, b_led, pot_0, pot_1, pot_2);
el16ttb 0:54721f063ac8 156 reset();
el16ttb 0:54721f063ac8 157 #endif
el16ttb 0:54721f063ac8 158 #ifndef IGNORE_TASK_7
el16ttb 0:54721f063ac8 159 printf("Task 7\n");
el16ttb 0:54721f063ac8 160 testAdmin.setTaskName("Task 7", &lcd, &streamOut);
el16ttb 0:54721f063ac8 161 waitRelease();
el16ttb 0:54721f063ac8 162 streamOut.writeMessage(0xf, 0x7);
el16ttb 0:54721f063ac8 163 streamOut.sendMessages();
el16ttb 0:54721f063ac8 164 Task7(testAdmin, r_led, button_a);
el16ttb 0:54721f063ac8 165 reset();
el16ttb 0:54721f063ac8 166 #endif
el16ttb 0:54721f063ac8 167 #ifndef IGNORE_TASK_8
el16ttb 0:54721f063ac8 168 printf("Task 8\n");
el16ttb 0:54721f063ac8 169 testAdmin.setTaskName("Task 8", &lcd, &streamOut);
el16ttb 0:54721f063ac8 170 waitRelease();
el16ttb 0:54721f063ac8 171 streamOut.writeMessage(0xf, 0x8);
el16ttb 0:54721f063ac8 172 streamOut.sendMessages();
el16ttb 0:54721f063ac8 173 Task8(testAdmin, leds);
el16ttb 0:54721f063ac8 174 reset();
el16ttb 0:54721f063ac8 175 #endif
el16ttb 0:54721f063ac8 176 #ifndef IGNORE_TASK_9
el16ttb 0:54721f063ac8 177 printf("Task 9\n");
el16ttb 0:54721f063ac8 178 testAdmin.setTaskName("Task 9", &lcd, &streamOut);
el16ttb 0:54721f063ac8 179 waitRelease();
el16ttb 0:54721f063ac8 180 streamOut.writeMessage(0xf, 0x9);
el16ttb 0:54721f063ac8 181 streamOut.sendMessages();
el16ttb 0:54721f063ac8 182 Task9(testAdmin, shift);
el16ttb 0:54721f063ac8 183 reset();
el16ttb 0:54721f063ac8 184 #endif
el16ttb 0:54721f063ac8 185 #ifndef IGNORE_TASK_10
el16ttb 0:54721f063ac8 186 printf("Task 10\n");
el16ttb 0:54721f063ac8 187 testAdmin.setTaskName("Task 10", &lcd, &streamOut);
el16ttb 0:54721f063ac8 188 waitRelease();
el16ttb 0:54721f063ac8 189 streamOut.writeMessage(0xf, 0xA);
el16ttb 0:54721f063ac8 190 streamOut.sendMessages();
el16ttb 0:54721f063ac8 191 Task10(testAdmin, shift, pot_0, pot_1);
el16ttb 0:54721f063ac8 192 reset();
el16ttb 0:54721f063ac8 193 #endif
el16ttb 0:54721f063ac8 194 #ifndef IGNORE_TASK_11
el16ttb 0:54721f063ac8 195 printf("Task 11\n");
el16ttb 0:54721f063ac8 196 testAdmin.setTaskName("Task 11", &lcd, &streamOut);
el16ttb 0:54721f063ac8 197 waitRelease();
el16ttb 0:54721f063ac8 198 streamOut.writeMessage(0xf, 0xB);
el16ttb 0:54721f063ac8 199 streamOut.sendMessages();
el16ttb 0:54721f063ac8 200 Task11(testAdmin, shift, button_a, button_b);
el16ttb 0:54721f063ac8 201 reset();
el16ttb 0:54721f063ac8 202 #endif
el16ttb 0:54721f063ac8 203 }
el16ttb 0:54721f063ac8 204 }