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 "exam.h"
el16ttb 0:54721f063ac8 2
el16ttb 0:54721f063ac8 3 // Task 1
el16ttb 0:54721f063ac8 4 // Hold A to turn the Red LED on. Let go to turn off
el16ttb 0:54721f063ac8 5 // (3 marks)
el16ttb 0:54721f063ac8 6 void Task1(TestAdmin &tester, PwmOut &r_led, DigitalIn &button_a){
el16ttb 0:54721f063ac8 7
el16ttb 0:54721f063ac8 8 while(tester.testRunning()){
el16ttb 0:54721f063ac8 9
el16ttb 0:54721f063ac8 10 }
el16ttb 0:54721f063ac8 11 }
el16ttb 0:54721f063ac8 12
el16ttb 0:54721f063ac8 13 // Task 2
el16ttb 0:54721f063ac8 14 // A - > Red, B -> Green, C -> Blue: Hold to turn on, release to turn off
el16ttb 0:54721f063ac8 15 // (3 marks)
el16ttb 0:54721f063ac8 16 void Task2(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, PwmOut &b_led, DigitalIn &button_a, DigitalIn &button_b, DigitalIn &button_c){
el16ttb 0:54721f063ac8 17
el16ttb 0:54721f063ac8 18 while(tester.testRunning()){
el16ttb 0:54721f063ac8 19
el16ttb 0:54721f063ac8 20 }
el16ttb 0:54721f063ac8 21 }
el16ttb 0:54721f063ac8 22
el16ttb 0:54721f063ac8 23 // Task 3
el16ttb 0:54721f063ac8 24 // Blue LED is the XOR of A and B
el16ttb 0:54721f063ac8 25 // (i.e. LED is on only when either of the buttons are pressed but not if both)
el16ttb 0:54721f063ac8 26 // (3 marks)
el16ttb 0:54721f063ac8 27 void Task3(TestAdmin &tester, PwmOut &b_led, DigitalIn &button_a, DigitalIn &button_b){
el16ttb 0:54721f063ac8 28
el16ttb 0:54721f063ac8 29 while(tester.testRunning()){
el16ttb 0:54721f063ac8 30
el16ttb 0:54721f063ac8 31 }
el16ttb 0:54721f063ac8 32 }
el16ttb 0:54721f063ac8 33
el16ttb 0:54721f063ac8 34 // Task 4
el16ttb 0:54721f063ac8 35 // Print the temperature measured with the temperature sensor as an integer over serial (using the following formula: 100 V - 50
el16ttb 0:54721f063ac8 36 // Print every value in a new line
el16ttb 0:54721f063ac8 37 // (3 marks)
el16ttb 0:54721f063ac8 38 void Task4(TestAdmin &tester, AnalogIn &temp){
el16ttb 0:54721f063ac8 39
el16ttb 0:54721f063ac8 40 while(tester.testRunning()){
el16ttb 0:54721f063ac8 41
el16ttb 0:54721f063ac8 42 }
el16ttb 0:54721f063ac8 43 }
el16ttb 0:54721f063ac8 44
el16ttb 0:54721f063ac8 45 // Task 5
el16ttb 0:54721f063ac8 46 // Green LED if the LDR can see light, Red LED if the LDR is covered
el16ttb 0:54721f063ac8 47 // (3 marks)
el16ttb 0:54721f063ac8 48 void Task5(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, AnalogIn &ldr){
el16ttb 0:54721f063ac8 49
el16ttb 0:54721f063ac8 50 while(tester.testRunning()){
el16ttb 0:54721f063ac8 51
el16ttb 0:54721f063ac8 52 }
el16ttb 0:54721f063ac8 53 }
el16ttb 0:54721f063ac8 54
el16ttb 0:54721f063ac8 55 // Task 6
el16ttb 0:54721f063ac8 56 // Pot0 -> Red, Pot1 -> Green, Pot2 -> Blue: use the potentiometers to set the brightness of each LED
el16ttb 0:54721f063ac8 57 // between fully off (when turned all the way to the left) and fully on (when turned all the way to the right)
el16ttb 0:54721f063ac8 58 // (3 marks)
el16ttb 0:54721f063ac8 59 void Task6(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, PwmOut &b_led, AnalogIn &pot_0, AnalogIn &pot_1, AnalogIn &pot_2){
el16ttb 0:54721f063ac8 60
el16ttb 0:54721f063ac8 61 while(tester.testRunning()){
el16ttb 0:54721f063ac8 62
el16ttb 0:54721f063ac8 63 }
el16ttb 0:54721f063ac8 64 }
el16ttb 0:54721f063ac8 65
el16ttb 0:54721f063ac8 66
el16ttb 0:54721f063ac8 67 // Task 7
el16ttb 0:54721f063ac8 68 // Toggle the Red LED i.e. Press A to turn on, press again to turn off
el16ttb 0:54721f063ac8 69 // (4 marks)
el16ttb 0:54721f063ac8 70 void Task7(TestAdmin &tester, PwmOut &r_led, DigitalIn &button_a){
el16ttb 0:54721f063ac8 71
el16ttb 0:54721f063ac8 72 while(tester.testRunning()){
el16ttb 0:54721f063ac8 73
el16ttb 0:54721f063ac8 74 }
el16ttb 0:54721f063ac8 75 }
el16ttb 0:54721f063ac8 76
el16ttb 0:54721f063ac8 77 // Task 8
el16ttb 0:54721f063ac8 78 // Display the following pattern on repeat on the LEDs with a 0.5s delay
el16ttb 0:54721f063ac8 79 // 0: | O | | | |
el16ttb 0:54721f063ac8 80 // 1: | | O | | |
el16ttb 0:54721f063ac8 81 // 2: | | | O | |
el16ttb 0:54721f063ac8 82 // 3: | | | | O |
el16ttb 0:54721f063ac8 83 // 4: | | | O | |
el16ttb 0:54721f063ac8 84 // 5: | | O | | |
el16ttb 0:54721f063ac8 85 // (4 marks)
el16ttb 0:54721f063ac8 86 void Task8(TestAdmin &tester, BusOut &leds){
el16ttb 0:54721f063ac8 87
el16ttb 0:54721f063ac8 88 while(tester.testRunning()){
el16ttb 0:54721f063ac8 89
el16ttb 0:54721f063ac8 90 }
el16ttb 0:54721f063ac8 91 }
el16ttb 0:54721f063ac8 92
el16ttb 0:54721f063ac8 93
el16ttb 0:54721f063ac8 94 // Task 9
el16ttb 0:54721f063ac8 95 // Display the following pattern on the seven segmented display
el16ttb 0:54721f063ac8 96 //
el16ttb 0:54721f063ac8 97 // | |
el16ttb 0:54721f063ac8 98 // |___|
el16ttb 0:54721f063ac8 99 // | |
el16ttb 0:54721f063ac8 100 // | |
el16ttb 0:54721f063ac8 101 // (4 marks)
el16ttb 0:54721f063ac8 102 void Task9(TestAdmin &tester, ShiftReg &shift){
el16ttb 0:54721f063ac8 103
el16ttb 0:54721f063ac8 104 while(tester.testRunning()){
el16ttb 0:54721f063ac8 105
el16ttb 0:54721f063ac8 106 }
el16ttb 0:54721f063ac8 107 }
el16ttb 0:54721f063ac8 108
el16ttb 0:54721f063ac8 109 // Task 10
el16ttb 0:54721f063ac8 110 // Use the joystick to set the following patterns on the seven segmented display
el16ttb 0:54721f063ac8 111 // (5 marks)
el16ttb 0:54721f063ac8 112 void Task10(TestAdmin &tester, ShiftReg &shift, AnalogIn &joy_v, AnalogIn &joy_h){
el16ttb 0:54721f063ac8 113
el16ttb 0:54721f063ac8 114 while(tester.testRunning()){
el16ttb 0:54721f063ac8 115
el16ttb 0:54721f063ac8 116 }
el16ttb 0:54721f063ac8 117 }
el16ttb 0:54721f063ac8 118
el16ttb 0:54721f063ac8 119 // Task 11
el16ttb 0:54721f063ac8 120 // Count up 0->9 on the seven segmented display when A pressed and down when B pressed
el16ttb 0:54721f063ac8 121 // (cycle around from 0 to 9 and 9 to 0)
el16ttb 0:54721f063ac8 122 // (5 marks)
el16ttb 0:54721f063ac8 123 void Task11(TestAdmin &tester, ShiftReg &shift, DigitalIn &button_a, DigitalIn &button_b){
el16ttb 0:54721f063ac8 124
el16ttb 0:54721f063ac8 125 while(tester.testRunning()){
el16ttb 0:54721f063ac8 126
el16ttb 0:54721f063ac8 127 }
el16ttb 0:54721f063ac8 128 }