MP3-capable chair with sensor-embedded weight scale.

Dependencies:   ACM1602 SDFileSystem VS1053 mbed ClockControl PowerControl

Files at this revision

API Documentation at this revision

Comitter:
kayekss
Date:
Tue Apr 01 16:19:56 2014 +0000
Parent:
2:844bedc9dc63
Commit message:
(1) Photo sensor input is digitized as the circuitry adds an external Schmitt-Trigger (2) Input Selector switch's logic is inverted

Changed in this revision

HysteresisIn.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 844bedc9dc63 -r 64f0ba828a2e HysteresisIn.lib
--- a/HysteresisIn.lib	Sat Mar 29 16:19:42 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/kayekss/code/HysteresisIn/#fe43537bd3d6
diff -r 844bedc9dc63 -r 64f0ba828a2e main.cpp
--- a/main.cpp	Sat Mar 29 16:19:42 2014 +0000
+++ b/main.cpp	Tue Apr 01 16:19:56 2014 +0000
@@ -1,7 +1,6 @@
 #include <stdio.h>
 #include "mbed.h"
 #include "defs.h"
-#include "HysteresisIn.h"
 #include "SDFileSystem.h"
 #include "VS1053.h"
 #include "ACM1602.h"
@@ -13,16 +12,14 @@
 SDFileSystem sd(/*MOSI*/ p11, /*MISO*/ p12, /*SCK*/ p13, /*CS*/ p21, /*Mountpoint*/ "sd");
 VS1053       mp3(/*MOSI*/ p11, /*MISO*/ p12, /*SCK*/ p13,
                  /*CS*/ p22, /*BSYNC*/ p23, /*DREQ*/ p24, /*RST*/ p25, /*SPI freq.*/ 4000000);
-HysteresisIn sens3(p17, H_TO_L_THRES, L_TO_H_THRES, 1);  // Photo sensor #3 (Outer)
-HysteresisIn sens2(p18, H_TO_L_THRES, L_TO_H_THRES, 1);  // Photo sensor #2
-HysteresisIn sens1(p19, H_TO_L_THRES, L_TO_H_THRES, 1);  // Photo sensor #1
-HysteresisIn sens0(p20, H_TO_L_THRES, L_TO_H_THRES, 1);  // Photo sensor #0 (Inner)
+BusIn        sens(/*Out: 0*/ p20, /*1*/ p19, /*2*/ p18, /*In: 3*/ p17);
+BusIn        test(/*Out: 0*/ p26, /*1*/ p27, /*2*/ p28, /*In: 3*/ p29);
 ACM1602      lcd(/*SDA*/ p9, /*SCL*/ p10, /*Address*/ 0xa0);
 DigitalOut   audioPower(p30);
-DigitalIn    test3(p17);
-DigitalIn    test2(p18);
-DigitalIn    test1(p19);
-DigitalIn    test0(p20);
+DigitalIn    test3(p29);
+DigitalIn    test2(p28);
+DigitalIn    test1(p27);
+DigitalIn    test0(p26);
 DigitalIn    inputSelector(p8);
 // Set unused pins to input when using the LPCXpresso board
 BusIn        __dummy(xp21, xp22, xp23, xp24, xp49, xp50, xp51, xp52, xp53);
@@ -43,7 +40,7 @@
 /** Setup and initializations */
 void setup(void) {
     // Reduce system clock frequency to 48 MHz
-    setSystemFrequency(0x3, 0x1, 6, 1);
+    setSystemFrequency(0x03, 0x01, 6, 1);
     
     // Power down Ethernet PHY
     PHY_PowerDown();
@@ -77,15 +74,12 @@
     
     // Read all photo sensor inputs
     if (inputFrom) {
-        bitPattern =   (test3 << 3)
-                     | (test2 << 2)
-                     | (test1 << 1)
-                     |  test0;
+        // Read from photo sensors when Input Selector reads high
+        // (Input is inverted by 74HC14)
+        bitPattern = ~sens & 0xf;
     } else {
-        bitPattern =   (sens3.read() << 3)
-                     | (sens2.read() << 2)
-                     | (sens1.read() << 1)
-                     |  sens0.read();
+        // Read from test pins when Input Selector reads low
+        bitPattern = test;
     }
     
     switch (bitPattern) {