A simple program built with mbed and a Nokia N3310LCD screen. Using the USB serial and any terminal application, you can change the brightness to 4 led's. Instructions are on the screen to start. Enjoy and have fun! All feedback is welcome. Please email: d.b.searle@reading.ac.uk

Dependencies:   N3310LCD mbed-rtos mbed Functions

Welcome

A simple program built with mbed and a Nokia N3310LCD screen. Using the USB serial and any terminal application, you can change the brightness to 4 led's. Instructions are on the screen to start. Enjoy and have fun! All feedback is welcome. Please email: d.b.searle@reading.ac.uk

Committer:
Searle95
Date:
Mon Jul 29 15:37:54 2013 +0000
Revision:
1:69297d522e83
Parent:
0:1a5ac0d2b2f6
Child:
6:477c2c8458e4
Updated rtos with official mbed-rtos.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Searle95 0:1a5ac0d2b2f6 1 #include "mbed.h"
Searle95 0:1a5ac0d2b2f6 2 #include "N3310SPIConfig.h"
Searle95 0:1a5ac0d2b2f6 3 #include "N3310LCD.h"
Searle95 0:1a5ac0d2b2f6 4 #include "rtos.h"
Searle95 0:1a5ac0d2b2f6 5 #include <string>
Searle95 0:1a5ac0d2b2f6 6
Searle95 1:69297d522e83 7 Serial pc(USBTX, USBRX);
Searle95 0:1a5ac0d2b2f6 8 PwmOut led1(LED1);
Searle95 0:1a5ac0d2b2f6 9 PwmOut led2(LED2);
Searle95 0:1a5ac0d2b2f6 10 PwmOut led3(LED3);
Searle95 0:1a5ac0d2b2f6 11 PwmOut led4(LED4);
Searle95 0:1a5ac0d2b2f6 12
Searle95 0:1a5ac0d2b2f6 13 N3310LCD lcd(N3310SPIPort::MOSI, N3310SPIPort::MISO, N3310SPIPort::SCK, N3310SPIPort::CE, N3310SPIPort::DAT_CMD, N3310SPIPort::LCD_RST, N3310SPIPort::BL_ON);
Searle95 0:1a5ac0d2b2f6 14
Searle95 0:1a5ac0d2b2f6 15 double all_bright = 0.0;
Searle95 0:1a5ac0d2b2f6 16 double led1_bright = 0.0;
Searle95 0:1a5ac0d2b2f6 17 double led2_bright = 0.0;
Searle95 0:1a5ac0d2b2f6 18 double led3_bright = 0.0;
Searle95 0:1a5ac0d2b2f6 19 double led4_bright = 0.0;
Searle95 0:1a5ac0d2b2f6 20
Searle95 0:1a5ac0d2b2f6 21 int main() {
Searle95 0:1a5ac0d2b2f6 22 lcd.init();
Searle95 0:1a5ac0d2b2f6 23 lcd.cls();
Searle95 1:69297d522e83 24
Searle95 0:1a5ac0d2b2f6 25 int main;
Searle95 0:1a5ac0d2b2f6 26 int line;
Searle95 0:1a5ac0d2b2f6 27 int loop;
Searle95 0:1a5ac0d2b2f6 28
Searle95 0:1a5ac0d2b2f6 29 main = 0;
Searle95 0:1a5ac0d2b2f6 30 line = 0;
Searle95 0:1a5ac0d2b2f6 31 loop = 0;
Searle95 0:1a5ac0d2b2f6 32
Searle95 0:1a5ac0d2b2f6 33 while(main < 1) {
Searle95 0:1a5ac0d2b2f6 34 lcd.cls();
Searle95 0:1a5ac0d2b2f6 35 lcd.writeString(19, 2, "Welcome!", NORMAL);
Searle95 0:1a5ac0d2b2f6 36 wait(2);
Searle95 0:1a5ac0d2b2f6 37 lcd.cls();
Searle95 0:1a5ac0d2b2f6 38 lcd.writeString(25, 0, "Intro", NORMAL);
Searle95 0:1a5ac0d2b2f6 39 lcd.writeString(2, 2, "Continue = c", NORMAL);
Searle95 0:1a5ac0d2b2f6 40 lcd.writeString(2, 3, "Skip = x", NORMAL);
Searle95 0:1a5ac0d2b2f6 41 char c = pc.getc();
Searle95 0:1a5ac0d2b2f6 42 if(c == 'x') {
Searle95 0:1a5ac0d2b2f6 43 lcd.cls();
Searle95 0:1a5ac0d2b2f6 44 lcd.writeString(10, 2, "Please wait", NORMAL);
Searle95 0:1a5ac0d2b2f6 45 main += 1;
Searle95 0:1a5ac0d2b2f6 46 break;
Searle95 0:1a5ac0d2b2f6 47 }
Searle95 0:1a5ac0d2b2f6 48 else if(c == 'c') {
Searle95 0:1a5ac0d2b2f6 49 lcd.cls();
Searle95 0:1a5ac0d2b2f6 50 lcd.printf(" All = q ");
Searle95 0:1a5ac0d2b2f6 51 lcd.printf(" LED 1 = w & a");
Searle95 0:1a5ac0d2b2f6 52 lcd.printf(" LED 2 = e & s");
Searle95 0:1a5ac0d2b2f6 53 lcd.printf(" LED 3 = r & d");
Searle95 0:1a5ac0d2b2f6 54 lcd.printf(" LED 4 = t & f");
Searle95 0:1a5ac0d2b2f6 55 lcd.printf(" All = y ");
Searle95 0:1a5ac0d2b2f6 56 wait(5);
Searle95 0:1a5ac0d2b2f6 57 lcd.cls();
Searle95 0:1a5ac0d2b2f6 58 lcd.writeString(10, 2, "Please wait", NORMAL);
Searle95 0:1a5ac0d2b2f6 59 main += 1;
Searle95 0:1a5ac0d2b2f6 60 }
Searle95 0:1a5ac0d2b2f6 61 }
Searle95 0:1a5ac0d2b2f6 62
Searle95 0:1a5ac0d2b2f6 63 while(loop < 82) {
Searle95 0:1a5ac0d2b2f6 64 wait(0.05);
Searle95 0:1a5ac0d2b2f6 65 lcd.writeString(line, 2, ".", NORMAL);
Searle95 0:1a5ac0d2b2f6 66 line += 1;
Searle95 0:1a5ac0d2b2f6 67 if(line == 82) {
Searle95 0:1a5ac0d2b2f6 68 lcd.cls();
Searle95 0:1a5ac0d2b2f6 69 lcd.writeString(25, 2, "Ready!", NORMAL);
Searle95 0:1a5ac0d2b2f6 70 }
Searle95 0:1a5ac0d2b2f6 71 loop += 1;
Searle95 0:1a5ac0d2b2f6 72 }
Searle95 0:1a5ac0d2b2f6 73
Searle95 0:1a5ac0d2b2f6 74 while(1){
Searle95 0:1a5ac0d2b2f6 75 char c = pc.getc();
Searle95 0:1a5ac0d2b2f6 76 if((c == 'q') && (all_bright < 0.9)) {
Searle95 0:1a5ac0d2b2f6 77 led1_bright += 1.0;
Searle95 0:1a5ac0d2b2f6 78 led2_bright += 1.0;
Searle95 0:1a5ac0d2b2f6 79 led3_bright += 1.0;
Searle95 0:1a5ac0d2b2f6 80 led4_bright += 1.0;
Searle95 0:1a5ac0d2b2f6 81 all_bright += 1.0;
Searle95 0:1a5ac0d2b2f6 82 led1 = led1_bright;
Searle95 0:1a5ac0d2b2f6 83 led2 = led2_bright;
Searle95 0:1a5ac0d2b2f6 84 led3 = led3_bright;
Searle95 0:1a5ac0d2b2f6 85 led4 = led4_bright;
Searle95 0:1a5ac0d2b2f6 86 lcd.cls();
Searle95 0:1a5ac0d2b2f6 87 lcd.writeString(5, 2, "All LED's On!", NORMAL);
Searle95 0:1a5ac0d2b2f6 88 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 89 lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright);
Searle95 0:1a5ac0d2b2f6 90 }
Searle95 0:1a5ac0d2b2f6 91
Searle95 0:1a5ac0d2b2f6 92 if((c == 'y') && (all_bright > 0.0)) {
Searle95 0:1a5ac0d2b2f6 93 led1_bright -= 1.0;
Searle95 0:1a5ac0d2b2f6 94 led2_bright -= 1.0;
Searle95 0:1a5ac0d2b2f6 95 led3_bright -= 1.0;
Searle95 0:1a5ac0d2b2f6 96 led4_bright -= 1.0;
Searle95 0:1a5ac0d2b2f6 97 all_bright -= 1.0;
Searle95 0:1a5ac0d2b2f6 98 led1 = led1_bright;
Searle95 0:1a5ac0d2b2f6 99 led2 = led2_bright;
Searle95 0:1a5ac0d2b2f6 100 led3 = led3_bright;
Searle95 0:1a5ac0d2b2f6 101 led4 = led4_bright;
Searle95 0:1a5ac0d2b2f6 102 if(all_bright < 0.00) {
Searle95 0:1a5ac0d2b2f6 103 all_bright = 0;
Searle95 0:1a5ac0d2b2f6 104 }
Searle95 0:1a5ac0d2b2f6 105 lcd.cls();
Searle95 0:1a5ac0d2b2f6 106 lcd.writeString(2, 2, "All LED's Off!", NORMAL);
Searle95 0:1a5ac0d2b2f6 107 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 108 lcd.printf("\n\n\n\n\n\n\n\n\n%g", all_bright);
Searle95 0:1a5ac0d2b2f6 109 }
Searle95 0:1a5ac0d2b2f6 110
Searle95 0:1a5ac0d2b2f6 111 if((c == 'w') && (led1_bright < 0.9)) {
Searle95 0:1a5ac0d2b2f6 112 led1_bright += 0.1;
Searle95 0:1a5ac0d2b2f6 113 led1 = led1_bright;
Searle95 0:1a5ac0d2b2f6 114 lcd.cls();
Searle95 0:1a5ac0d2b2f6 115 lcd.writeString(15, 2, "LED 1 Up!", NORMAL);
Searle95 0:1a5ac0d2b2f6 116 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 117 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright);
Searle95 0:1a5ac0d2b2f6 118 }
Searle95 0:1a5ac0d2b2f6 119
Searle95 0:1a5ac0d2b2f6 120 if((c == 'a') && (led1_bright > 0.0)) {
Searle95 0:1a5ac0d2b2f6 121 led1_bright -= 0.1;
Searle95 0:1a5ac0d2b2f6 122 led1 = led1_bright;
Searle95 0:1a5ac0d2b2f6 123 if(led1_bright < 0.00) {
Searle95 0:1a5ac0d2b2f6 124 led1_bright = 0;
Searle95 0:1a5ac0d2b2f6 125 }
Searle95 0:1a5ac0d2b2f6 126 lcd.cls();
Searle95 0:1a5ac0d2b2f6 127 lcd.writeString(10, 2, "LED 1 Down!", NORMAL);
Searle95 0:1a5ac0d2b2f6 128 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 129 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led1_bright);
Searle95 0:1a5ac0d2b2f6 130 }
Searle95 0:1a5ac0d2b2f6 131
Searle95 0:1a5ac0d2b2f6 132 if((c == 'e') && (led2_bright < 0.9)) {
Searle95 0:1a5ac0d2b2f6 133 led2_bright += 0.1;
Searle95 0:1a5ac0d2b2f6 134 led2 = led2_bright;
Searle95 0:1a5ac0d2b2f6 135 lcd.cls();
Searle95 0:1a5ac0d2b2f6 136 lcd.writeString(15, 2, "LED 2 Up!", NORMAL);
Searle95 0:1a5ac0d2b2f6 137 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 138 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright);
Searle95 0:1a5ac0d2b2f6 139 }
Searle95 0:1a5ac0d2b2f6 140
Searle95 0:1a5ac0d2b2f6 141 if((c == 's') && (led2_bright > 0.0)) {
Searle95 0:1a5ac0d2b2f6 142 led2_bright -= 0.1;
Searle95 0:1a5ac0d2b2f6 143 led2 = led2_bright;
Searle95 0:1a5ac0d2b2f6 144 if(led2_bright < 0.00) {
Searle95 0:1a5ac0d2b2f6 145 led2_bright = 0;
Searle95 0:1a5ac0d2b2f6 146 }
Searle95 0:1a5ac0d2b2f6 147 lcd.cls();
Searle95 0:1a5ac0d2b2f6 148 lcd.writeString(10, 2, "LED 2 Down!", NORMAL);
Searle95 0:1a5ac0d2b2f6 149 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 150 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led2_bright);
Searle95 0:1a5ac0d2b2f6 151 }
Searle95 0:1a5ac0d2b2f6 152
Searle95 0:1a5ac0d2b2f6 153 if((c == 'r') && (led3_bright < 0.9)) {
Searle95 0:1a5ac0d2b2f6 154 led3_bright += 0.1;
Searle95 0:1a5ac0d2b2f6 155 led3 = led3_bright;
Searle95 0:1a5ac0d2b2f6 156 lcd.cls();
Searle95 0:1a5ac0d2b2f6 157 lcd.writeString(15, 2, "LED 3 Up!", NORMAL);
Searle95 0:1a5ac0d2b2f6 158 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 159 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright);
Searle95 0:1a5ac0d2b2f6 160 }
Searle95 0:1a5ac0d2b2f6 161
Searle95 0:1a5ac0d2b2f6 162 if((c == 'd') && (led3_bright > 0.0)) {
Searle95 0:1a5ac0d2b2f6 163 led3_bright -= 0.1;
Searle95 0:1a5ac0d2b2f6 164 led3 = led3_bright;
Searle95 0:1a5ac0d2b2f6 165 if(led3_bright < 0.00) {
Searle95 0:1a5ac0d2b2f6 166 led3_bright = 0;
Searle95 0:1a5ac0d2b2f6 167 }
Searle95 0:1a5ac0d2b2f6 168 lcd.cls();
Searle95 0:1a5ac0d2b2f6 169 lcd.writeString(10, 2, "LED 3 Down!", NORMAL);
Searle95 0:1a5ac0d2b2f6 170 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 171 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led3_bright);
Searle95 0:1a5ac0d2b2f6 172 }
Searle95 0:1a5ac0d2b2f6 173
Searle95 0:1a5ac0d2b2f6 174 if((c == 't') && (led4_bright < 0.9)) {
Searle95 0:1a5ac0d2b2f6 175 led4_bright += 0.1;
Searle95 0:1a5ac0d2b2f6 176 led4 = led4_bright;
Searle95 0:1a5ac0d2b2f6 177 lcd.cls();
Searle95 0:1a5ac0d2b2f6 178 lcd.writeString(15, 2, "LED 4 Up!", NORMAL);
Searle95 0:1a5ac0d2b2f6 179 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 180 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright);
Searle95 0:1a5ac0d2b2f6 181 }
Searle95 0:1a5ac0d2b2f6 182
Searle95 0:1a5ac0d2b2f6 183 if((c == 'f') && (led4_bright > 0.0)) {
Searle95 0:1a5ac0d2b2f6 184 led4_bright -= 0.1;
Searle95 0:1a5ac0d2b2f6 185 led4 = led4_bright;
Searle95 0:1a5ac0d2b2f6 186 if(led4_bright < 0.00) {
Searle95 0:1a5ac0d2b2f6 187 led4_bright = 0;
Searle95 0:1a5ac0d2b2f6 188 }
Searle95 0:1a5ac0d2b2f6 189 lcd.cls();
Searle95 0:1a5ac0d2b2f6 190 lcd.writeString(10, 2, "LED 4 Down!", NORMAL);
Searle95 0:1a5ac0d2b2f6 191 lcd.writeString(13, 4, "Brightness", NORMAL);
Searle95 0:1a5ac0d2b2f6 192 lcd.printf("\n\n\n\n\n\n\n\n\n%g", led4_bright);
Searle95 0:1a5ac0d2b2f6 193 }
Searle95 0:1a5ac0d2b2f6 194
Searle95 0:1a5ac0d2b2f6 195 if(c == 'z') {
Searle95 0:1a5ac0d2b2f6 196 lcd.cls();
Searle95 0:1a5ac0d2b2f6 197 lcd.writeString(25, 2, "System", NORMAL);
Searle95 0:1a5ac0d2b2f6 198 lcd.writeString(23, 3, "Restart", NORMAL);
Searle95 0:1a5ac0d2b2f6 199 all_bright = 1;
Searle95 0:1a5ac0d2b2f6 200 led1 = all_bright;
Searle95 0:1a5ac0d2b2f6 201 led2 = all_bright;
Searle95 0:1a5ac0d2b2f6 202 led3 = all_bright;
Searle95 0:1a5ac0d2b2f6 203 led4 = all_bright;
Searle95 0:1a5ac0d2b2f6 204 wait(2);
Searle95 0:1a5ac0d2b2f6 205 NVIC_SystemReset();
Searle95 0:1a5ac0d2b2f6 206 }
Searle95 0:1a5ac0d2b2f6 207 }
Searle95 0:1a5ac0d2b2f6 208 }