Project Template for Headstart Course 2017

Dependencies:   N5110 ShiftReg Tone mbed

Fork of 1620_Project_Template by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Wed Mar 08 20:05:58 2017 +0000
Child:
1:76241e21ec61
Commit message:
Initial commit

Changed in this revision

Main/main.cpp Show annotated file Show diff for this revision Revisions of this file
Main/main.h Show annotated file Show diff for this revision Revisions of this file
ModeA/ModeA.cpp Show annotated file Show diff for this revision Revisions of this file
ModeA/ModeA.h Show annotated file Show diff for this revision Revisions of this file
ModeB/ModeB.cpp Show annotated file Show diff for this revision Revisions of this file
ModeB/ModeB.h Show annotated file Show diff for this revision Revisions of this file
ModeC/ModeC.cpp Show annotated file Show diff for this revision Revisions of this file
ModeC/ModeC.h Show annotated file Show diff for this revision Revisions of this file
ModeD/ModeD.cpp Show annotated file Show diff for this revision Revisions of this file
ModeD/ModeD.h Show annotated file Show diff for this revision Revisions of this file
N5110.lib Show annotated file Show diff for this revision Revisions of this file
ShiftReg.lib Show annotated file Show diff for this revision Revisions of this file
Tone.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main/main.cpp	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,98 @@
+#include "main.h"
+
+// objects defined here with pin numbers (if required)
+DigitalIn button_a(p29);
+DigitalIn button_b(p28);
+DigitalIn button_c(p27);
+DigitalIn button_d(p26);
+
+N5110 lcd(p8,p9,p10,p11,p13,p21);
+BusOut leds(LED4,LED3,LED2,LED1);
+
+AnalogIn ldr(p15);
+
+PwmOut red_led(p24);
+PwmOut green_led(p23);
+PwmOut blue_led(p22);
+
+AnalogIn tmp36(p16);
+
+AnalogIn pot_0(p20);
+AnalogIn pot_1(p19);
+AnalogIn pot_2(p17);
+
+Tone speaker(p18);
+ShiftReg shift;
+
+int main()
+{
+    init();  // initialise peripherals
+    welcome();  // display welcome message
+
+    while(1) {  // infinite loop
+
+        print_menu();  // this re-prints the menu at the start of every loop
+
+        // if any buttons pressed then jump to appropriate menu function
+        if (button_a.read() == 1) {
+            mode_A();
+        }
+        if (button_b.read() == 1) {
+            mode_B();
+        }
+        if (button_c.read() == 1) {
+            mode_C();
+        }
+        if (button_d.read() == 1) {
+            mode_D();
+        }
+
+        // delay to prevent multiple button presses being detected
+        wait_ms(250);
+
+    }
+}
+
+void init()
+{
+    // turn off LEDs
+    red_led = 1.0;
+    green_led = 1.0;
+    blue_led = 1.0;
+    
+    // turn off 7-seg display
+    shift.write(0x00);
+
+    // initialise LCD
+    lcd.init();
+
+    // PCB has external pull-down resistors so turn the internal ones off
+    button_a.mode(PullNone);
+    button_b.mode(PullNone);
+    button_c.mode(PullNone);
+    button_d.mode(PullNone);
+}
+
+void print_menu()
+{
+    lcd.clear();
+    lcd.printString("Press button",0,0);
+    lcd.printString("to select",0,1);
+    lcd.printString("A: Mode A",0,2);
+    lcd.printString("B: Mode B",0,3);
+    lcd.printString("C: Mode C",0,4);
+    lcd.printString("D: Mode D",0,5);
+    lcd.refresh();
+}
+
+void welcome()
+{
+    lcd.clear();
+    lcd.printString("  Automotive",0,0);
+    lcd.printString("  Electronics",0,1);
+    lcd.printString("   Simulator",0,2);
+    lcd.printString("Craig A. Evans",0,4);
+    lcd.printString("  0123456789",0,5);
+    lcd.refresh();
+    wait(5.0);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main/main.h	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,45 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+// include the different header files
+#include "mbed.h"
+#include "N5110.h"
+#include "Shift.h"
+#include "Tone.h"
+#include "ModeA.h"
+#include "ModeB.h"
+#include "ModeC.h"
+#include "ModeD.h"
+
+// extern tells the compiler that these objects are defined in a different file (main.cpp).
+// It stops them being defined multiple times when other files include main.h.
+// Here we only declare them. They are defined (with pin numbers etc.) in main.cpp
+extern DigitalIn button_a;
+extern DigitalIn button_b;
+extern DigitalIn button_c;
+extern DigitalIn button_d;
+
+extern N5110 lcd;
+extern BusOut leds;
+
+extern AnalogIn ldr;
+
+extern PwmOut red_led;
+extern PwmOut green_led;
+extern PwmOut blue_led;
+
+extern AnalogIn tmp36;
+
+extern AnalogIn pot_0;
+extern AnalogIn pot_1;
+extern AnalogIn pot_2;
+
+extern Tone speaker;
+extern Shift;
+
+// function prototypes
+void init();
+void print_menu();
+void welcome();
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeA/ModeA.cpp	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,17 @@
+#include "ModeA.h"
+
+void mode_A() {
+    
+    lcd.clear();
+    lcd.printString("Mode A",0,0);
+    lcd.refresh();
+    wait_ms(250);  // small delay to prevent previous press being detected again
+
+    while (button_a.read() == 0) {
+        
+        // code goes in here - this acts like the main while(1) loop
+        
+
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeA/ModeA.h	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,11 @@
+#ifndef MODEA_H
+#define MODEA_H
+
+#include "mbed.h"
+#include "main.h"
+
+// function prototypes
+void mode_A();
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeB/ModeB.cpp	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,18 @@
+#include "ModeB.h"
+
+void mode_B()
+{
+
+    lcd.clear();
+    lcd.printString("Mode B",0,0);
+    lcd.refresh();
+    wait_ms(250);
+
+    while (button_b.read() == 0) {
+
+        // code goes in here - this acts like the main while(1) loop
+
+
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeB/ModeB.h	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,10 @@
+#ifndef MODEB_H
+#define MODEB_H
+
+#include "mbed.h"
+#include "main.h"
+
+// function prototypes
+void mode_B();
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeC/ModeC.cpp	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,18 @@
+#include "ModeC.h"
+
+void mode_C()
+{
+
+    lcd.clear();
+    lcd.printString("Mode C",0,0);
+    lcd.refresh();
+    wait_ms(250);  // small delay to prevent previous press being detected again
+
+    while (button_c.read() == 0) {
+
+        // code goes in here - this acts like the main while(1) loop
+
+
+    }
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeC/ModeC.h	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,11 @@
+#ifndef MODEC_H
+#define MODEC_H
+
+#include "mbed.h"
+#include "main.h"
+
+// function prototypes
+void mode_C();
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeD/ModeD.cpp	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,17 @@
+#include "ModeD.h"
+
+void mode_D() {
+    
+    lcd.clear();
+    lcd.printString("Mode D",0,0);
+    lcd.refresh();
+    wait_ms(250);
+
+    while (button_d.read() == 0) {
+        
+        // code goes in here - this acts like the main while(1) loop
+
+
+    }
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ModeD/ModeD.h	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,10 @@
+#ifndef MODED_H
+#define MODED_H
+
+#include "mbed.h"
+#include "main.h"
+
+// function prototypes
+void mode_D();
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/N5110/#d80e568a2e18
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ShiftReg.lib	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/ShiftReg/#33b34e0ed72c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Tone.lib	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/Tone/#836cdf67dbdb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Mar 08 20:05:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file