Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
exam.cpp@3:9fd187c3fd38, 2019-04-16 (annotated)
- Committer:
- el16ttb
- Date:
- Tue Apr 16 19:24:23 2019 +0000
- Revision:
- 3:9fd187c3fd38
- Parent:
- 2:f56d6bd8aa25
Fix typos
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:f56d6bd8aa25 | 7 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 8 | |
el16ttb | 3:9fd187c3fd38 | 9 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 10 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 11 | |
el16ttb | 2:f56d6bd8aa25 | 12 | } |
el16ttb | 0:54721f063ac8 | 13 | } |
el16ttb | 0:54721f063ac8 | 14 | |
el16ttb | 0:54721f063ac8 | 15 | // Task 2 |
el16ttb | 0:54721f063ac8 | 16 | // A - > Red, B -> Green, C -> Blue: Hold to turn on, release to turn off |
el16ttb | 0:54721f063ac8 | 17 | // (3 marks) |
el16ttb | 0:54721f063ac8 | 18 | void Task2(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, PwmOut &b_led, DigitalIn &button_a, DigitalIn &button_b, DigitalIn &button_c){ |
el16ttb | 2:f56d6bd8aa25 | 19 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 20 | |
el16ttb | 3:9fd187c3fd38 | 21 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 22 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 23 | |
el16ttb | 2:f56d6bd8aa25 | 24 | } |
el16ttb | 0:54721f063ac8 | 25 | } |
el16ttb | 0:54721f063ac8 | 26 | |
el16ttb | 0:54721f063ac8 | 27 | // Task 3 |
el16ttb | 0:54721f063ac8 | 28 | // Blue LED is the XOR of A and B |
el16ttb | 0:54721f063ac8 | 29 | // (i.e. LED is on only when either of the buttons are pressed but not if both) |
el16ttb | 0:54721f063ac8 | 30 | // (3 marks) |
el16ttb | 0:54721f063ac8 | 31 | void Task3(TestAdmin &tester, PwmOut &b_led, DigitalIn &button_a, DigitalIn &button_b){ |
el16ttb | 2:f56d6bd8aa25 | 32 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 33 | |
el16ttb | 3:9fd187c3fd38 | 34 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 35 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 36 | |
el16ttb | 2:f56d6bd8aa25 | 37 | } |
el16ttb | 0:54721f063ac8 | 38 | } |
el16ttb | 0:54721f063ac8 | 39 | |
el16ttb | 0:54721f063ac8 | 40 | // Task 4 |
el16ttb | 3:9fd187c3fd38 | 41 | // Print the temperature measured with the temperature sensor as an integer over serial (using the following formula: 100 V - 50) |
el16ttb | 0:54721f063ac8 | 42 | // Print every value in a new line |
el16ttb | 0:54721f063ac8 | 43 | // (3 marks) |
el16ttb | 0:54721f063ac8 | 44 | void Task4(TestAdmin &tester, AnalogIn &temp){ |
el16ttb | 2:f56d6bd8aa25 | 45 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 46 | |
el16ttb | 3:9fd187c3fd38 | 47 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 48 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 49 | |
el16ttb | 2:f56d6bd8aa25 | 50 | } |
el16ttb | 0:54721f063ac8 | 51 | } |
el16ttb | 0:54721f063ac8 | 52 | |
el16ttb | 0:54721f063ac8 | 53 | // Task 5 |
el16ttb | 0:54721f063ac8 | 54 | // Green LED if the LDR can see light, Red LED if the LDR is covered |
el16ttb | 0:54721f063ac8 | 55 | // (3 marks) |
el16ttb | 0:54721f063ac8 | 56 | void Task5(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, AnalogIn &ldr){ |
el16ttb | 2:f56d6bd8aa25 | 57 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 58 | |
el16ttb | 3:9fd187c3fd38 | 59 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 60 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 61 | |
el16ttb | 2:f56d6bd8aa25 | 62 | } |
el16ttb | 0:54721f063ac8 | 63 | } |
el16ttb | 0:54721f063ac8 | 64 | |
el16ttb | 0:54721f063ac8 | 65 | // Task 6 |
el16ttb | 0:54721f063ac8 | 66 | // Pot0 -> Red, Pot1 -> Green, Pot2 -> Blue: use the potentiometers to set the brightness of each LED |
el16ttb | 0:54721f063ac8 | 67 | // 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 | 68 | // (3 marks) |
el16ttb | 0:54721f063ac8 | 69 | void Task6(TestAdmin &tester, PwmOut &r_led, PwmOut &g_led, PwmOut &b_led, AnalogIn &pot_0, AnalogIn &pot_1, AnalogIn &pot_2){ |
el16ttb | 2:f56d6bd8aa25 | 70 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 71 | |
el16ttb | 3:9fd187c3fd38 | 72 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 73 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 74 | |
el16ttb | 2:f56d6bd8aa25 | 75 | } |
el16ttb | 0:54721f063ac8 | 76 | } |
el16ttb | 0:54721f063ac8 | 77 | |
el16ttb | 0:54721f063ac8 | 78 | |
el16ttb | 0:54721f063ac8 | 79 | // Task 7 |
el16ttb | 0:54721f063ac8 | 80 | // Toggle the Red LED i.e. Press A to turn on, press again to turn off |
el16ttb | 0:54721f063ac8 | 81 | // (4 marks) |
el16ttb | 0:54721f063ac8 | 82 | void Task7(TestAdmin &tester, PwmOut &r_led, DigitalIn &button_a){ |
el16ttb | 2:f56d6bd8aa25 | 83 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 84 | |
el16ttb | 3:9fd187c3fd38 | 85 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 86 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 87 | |
el16ttb | 2:f56d6bd8aa25 | 88 | } |
el16ttb | 0:54721f063ac8 | 89 | } |
el16ttb | 0:54721f063ac8 | 90 | |
el16ttb | 0:54721f063ac8 | 91 | // Task 8 |
el16ttb | 0:54721f063ac8 | 92 | // Display the following pattern on repeat on the LEDs with a 0.5s delay |
el16ttb | 0:54721f063ac8 | 93 | // 0: | O | | | | |
el16ttb | 0:54721f063ac8 | 94 | // 1: | | O | | | |
el16ttb | 0:54721f063ac8 | 95 | // 2: | | | O | | |
el16ttb | 0:54721f063ac8 | 96 | // 3: | | | | O | |
el16ttb | 0:54721f063ac8 | 97 | // 4: | | | O | | |
el16ttb | 0:54721f063ac8 | 98 | // 5: | | O | | | |
el16ttb | 0:54721f063ac8 | 99 | // (4 marks) |
el16ttb | 0:54721f063ac8 | 100 | void Task8(TestAdmin &tester, BusOut &leds){ |
el16ttb | 2:f56d6bd8aa25 | 101 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 102 | |
el16ttb | 3:9fd187c3fd38 | 103 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 104 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 105 | |
el16ttb | 2:f56d6bd8aa25 | 106 | } |
el16ttb | 0:54721f063ac8 | 107 | } |
el16ttb | 0:54721f063ac8 | 108 | |
el16ttb | 0:54721f063ac8 | 109 | |
el16ttb | 0:54721f063ac8 | 110 | // Task 9 |
el16ttb | 0:54721f063ac8 | 111 | // Display the following pattern on the seven segmented display |
el16ttb | 0:54721f063ac8 | 112 | // |
el16ttb | 0:54721f063ac8 | 113 | // | | |
el16ttb | 0:54721f063ac8 | 114 | // |___| |
el16ttb | 0:54721f063ac8 | 115 | // | | |
el16ttb | 0:54721f063ac8 | 116 | // | | |
el16ttb | 0:54721f063ac8 | 117 | // (4 marks) |
el16ttb | 0:54721f063ac8 | 118 | void Task9(TestAdmin &tester, ShiftReg &shift){ |
el16ttb | 2:f56d6bd8aa25 | 119 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 120 | |
el16ttb | 3:9fd187c3fd38 | 121 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 122 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 123 | |
el16ttb | 2:f56d6bd8aa25 | 124 | } |
el16ttb | 0:54721f063ac8 | 125 | } |
el16ttb | 0:54721f063ac8 | 126 | |
el16ttb | 0:54721f063ac8 | 127 | // Task 10 |
el16ttb | 0:54721f063ac8 | 128 | // Use the joystick to set the following patterns on the seven segmented display |
el16ttb | 0:54721f063ac8 | 129 | // (5 marks) |
el16ttb | 0:54721f063ac8 | 130 | void Task10(TestAdmin &tester, ShiftReg &shift, AnalogIn &joy_v, AnalogIn &joy_h){ |
el16ttb | 2:f56d6bd8aa25 | 131 | // Code here that executed at the start of the task |
el16ttb | 2:f56d6bd8aa25 | 132 | |
el16ttb | 3:9fd187c3fd38 | 133 | while(tester.testRunning()){ // Run until button D is pressed |
el16ttb | 2:f56d6bd8aa25 | 134 | // Code here that executed continously during the task |
el16ttb | 2:f56d6bd8aa25 | 135 | |
el16ttb | 2:f56d6bd8aa25 | 136 | } |
el16ttb | 0:54721f063ac8 | 137 | } |