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:
eendmo
Date:
Mon Jul 10 10:07:01 2017 +0000
Parent:
1:76241e21ec61
Child:
3:625925922d09
Commit message:
Project for Headstart Lab Session 2017

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 diff for this revision Revisions of this file
ModeC/ModeC.h Show diff for this revision Revisions of this file
ModeD/ModeD.cpp Show diff for this revision Revisions of this file
ModeD/ModeD.h Show diff for this revision Revisions of this file
N5110.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Main/main.cpp	Mon Mar 13 07:01:51 2017 +0000
+++ b/Main/main.cpp	Mon Jul 10 10:07:01 2017 +0000
@@ -22,7 +22,7 @@
 AnalogIn pot_2(p17);
 
 Tone speaker(p18);
-ShiftReg shift;
+ShiftReg sevenSeg;
 
 int main()
 {
@@ -41,10 +41,10 @@
             mode_B();
         }
         if (button_c.read() == 1) {
-            mode_C();
+
         }
         if (button_d.read() == 1) {
-            mode_D();
+
         }
 
         // delay to prevent multiple button presses being detected
@@ -60,8 +60,12 @@
     green_led = 1.0;
     blue_led = 1.0;
     
+    // set led PWM frequency
+    float frequency = 100.0f;
+    red_led.period(1.0f/frequency);
+    
     // turn off 7-seg display
-    shift.write(0x00);
+    sevenSeg.write(0x00);
 
     // initialise LCD
     lcd.init();
@@ -80,19 +84,16 @@
     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.printString("     UKESF",0,1);
+    lcd.printString("  Headstart",0,2);
+    lcd.printString(" Demo Board",0,3);
+    lcd.printString("YOUR NAME HERE",0,4);
     lcd.refresh();
     wait(5.0);
 }
\ No newline at end of file
--- a/Main/main.h	Mon Mar 13 07:01:51 2017 +0000
+++ b/Main/main.h	Mon Jul 10 10:07:01 2017 +0000
@@ -8,8 +8,6 @@
 #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.
@@ -35,7 +33,7 @@
 extern AnalogIn pot_2;
 
 extern Tone speaker;
-extern ShiftReg shift;
+extern ShiftReg sevenSeg;
 
 // function prototypes
 void init();
--- a/ModeA/ModeA.cpp	Mon Mar 13 07:01:51 2017 +0000
+++ b/ModeA/ModeA.cpp	Mon Jul 10 10:07:01 2017 +0000
@@ -5,13 +5,40 @@
     lcd.clear();
     lcd.printString("Mode A",0,0);
     lcd.refresh();
-    wait_ms(250);  // small delay to prevent previous press being detected again
+    wait_ms(250); 
+
+    int segments[10] = {}; // Enter your hex values here!
+    int count = 0;
+    
+    update_display(count, segments[count]);
 
     while (button_a.read() == 0) {
         
-        // code goes in here - this acts like the main while(1) loop
+        if(button_b.read() == 1){
+            count++;
+            update_display(count, segments[count]);
+            wait_ms(250);
+        }
+        if(button_d.read() == 1){
+            count--;
+            update_display(count, segments[count]);
+            wait_ms(250);
+        }
         
+        
+        sevenSeg.write(segments[count]);
 
     }
 
+}
+
+void update_display(int count, int hex){
+    char count_string[14];
+    sprintf(count_string, "Count = %d    ", count);
+    lcd.printString(count_string,0,2);   
+    char hex_string[14];
+    sprintf(hex_string, "Hex: %#04x     ", hex);
+    lcd.printString(hex_string,0,3);
+    lcd.refresh();
+    
 }
\ No newline at end of file
--- a/ModeA/ModeA.h	Mon Mar 13 07:01:51 2017 +0000
+++ b/ModeA/ModeA.h	Mon Jul 10 10:07:01 2017 +0000
@@ -4,8 +4,11 @@
 #include "mbed.h"
 #include "main.h"
 
+// I/O Declarations
+
 // function prototypes
 void mode_A();
+void update_display(int count, int hex);
 
 
 #endif
\ No newline at end of file
--- a/ModeB/ModeB.cpp	Mon Mar 13 07:01:51 2017 +0000
+++ b/ModeB/ModeB.cpp	Mon Jul 10 10:07:01 2017 +0000
@@ -1,18 +1,53 @@
 #include "ModeB.h"
 
+float voltage_a = 0.0;
+float voltage_b = 0.0;
+float voltage_c = 0.0;
+
 void mode_B()
 {
 
     lcd.clear();
     lcd.printString("Mode B",0,0);
     lcd.refresh();
+    update_display();
+    
     wait_ms(250);
 
     while (button_b.read() == 0) {
-
-        // code goes in here - this acts like the main while(1) loop
+        
+        //All code goes in here!
+        
+        
+        
+        
+        update_display();
 
 
     }
 
+}
+
+void update_display(){
+    
+    int red_percent = 100.0 - (red_led/1.0) * 100.0;
+    int blue_percent = 100.0 - (blue_led/1.0) * 100.0;
+    int green_percent = 100.0 -(green_led/1.0) * 100.0;
+    
+    char new_string[3];
+    lcd.printString("R    G    B   ",0,2);
+    sprintf(new_string, "%d%%  ", red_percent);
+    lcd.printString(new_string,0,3);
+    sprintf(new_string, "%d%%  ", green_percent);
+    lcd.printString(new_string,30,3);
+    sprintf(new_string, "%d%%  ", blue_percent);
+    lcd.printString(new_string,60,3);
+    sprintf(new_string, "%.1fV  ", voltage_a);
+    lcd.printString(new_string,0,3);
+    sprintf(new_string, "%.1fV  ", voltage_b);
+    lcd.printString(new_string,30,3);
+    sprintf(new_string, "%.1fV  ", voltage_c);
+    lcd.printString(new_string,60,3);
+    lcd.refresh();
+
 }
\ No newline at end of file
--- a/ModeB/ModeB.h	Mon Mar 13 07:01:51 2017 +0000
+++ b/ModeB/ModeB.h	Mon Jul 10 10:07:01 2017 +0000
@@ -6,5 +6,10 @@
 
 // function prototypes
 void mode_B();
+void update_display();
+
+// variable declarations
+
+
 
 #endif
\ No newline at end of file
--- a/ModeC/ModeC.cpp	Mon Mar 13 07:01:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#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
--- a/ModeC/ModeC.h	Mon Mar 13 07:01:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#ifndef MODEC_H
-#define MODEC_H
-
-#include "mbed.h"
-#include "main.h"
-
-// function prototypes
-void mode_C();
-
-
-#endif
\ No newline at end of file
--- a/ModeD/ModeD.cpp	Mon Mar 13 07:01:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-#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
--- a/ModeD/ModeD.h	Mon Mar 13 07:01:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#ifndef MODED_H
-#define MODED_H
-
-#include "mbed.h"
-#include "main.h"
-
-// function prototypes
-void mode_D();
-
-#endif
\ No newline at end of file
--- a/N5110.lib	Mon Mar 13 07:01:51 2017 +0000
+++ b/N5110.lib	Mon Jul 10 10:07:01 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/eencae/code/N5110/#d80e568a2e18
+http://mbed.org/users/eencae/code/N5110/#c2598020fcac