test

Dependencies:   mbed MMA8452Q

Fork of HelloWorld by Simon Ford

Revision:
27:0f602aca65f1
Parent:
26:523ac79471d8
Child:
28:f56de0b0764e
--- a/main.cpp	Fri Sep 08 01:54:02 2017 +0000
+++ b/main.cpp	Fri Sep 08 04:13:54 2017 +0000
@@ -4,13 +4,74 @@
 #include "MMA8452Q.h"
 
 Serial pc(USBTX, USBRX); // tx, rx
-SPI spi(p11,p12,p13);
-DigitalOut cs(p14);
+//SPI spi(p11,p12,p13);
+//DigitalOut cs(p14);
 // Communication I2C
 //I2C i2c(p9,p10); // sda, scl
 
+//int main() {
+  //  }
+    
+
+
+// on utilise l'afficheur 7 SEG en mode SPI pour la mise au point
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut cs(p8);
+
+AnalogOut signal(p18);
+AnalogIn ain(p20);
+BusOut myleds(LED1, LED2, LED3, LED4);  // for display 4 leds in hex format
+unsigned short value;
+Ticker display;
+
+short table[16] = { 0x00,   // 0 0 - 1/16
+                    0x00,   // 1 1/16 - 1/8
+                    0x01,   // 2 1/8 - 3/16
+                    0x01,   // 3 3/16 - 1/4
+                    0x01,   // 4 1/4 - 5/16
+                    0x01,   // 5 5/16 - 3/8
+                    0x03,   // 6 3/8 - 7/16
+                    0x03,   // 7 7/16 - 1/2
+                    0x03,   // 8 1/2 - 9/16
+                    0x03,   // 9 9/16 - 5/8
+                    0x07,   // a 5/8 - 11/16
+                    0x07,   // b 11/16 - 3/4
+                    0x07,   // c 3/4 - 13/16
+                    0x07,   // d 13/16 - 7/8
+                    0x0f,   // e 7/8 - 15/16
+                    0x0f};  // f 15/16 - 1
+
+void disp() {
+    short i;
+    value = ain.read_u16();  // read input
+    i = (value >> 12) & 0x000f;  // transform to hex
+    
+        cs = 0;         // affichage 7 SEG via SPI
+        wait_us(5);
+        spi.write(i); 
+        wait_us(5);
+        cs = 1;
+        
+    myleds = table[i];  // affichage sur les LEDs
+}
+
 int main() {
+   spi.format(8,0);     // initialisation du port SPI pour l'afficheur
+   spi.frequency(100000);
+   
+         cs = 0;
+         wait_us(5);
+         spi.write(0x76);   //clear
+         wait_us(5);
+         cs = 1;
+         
+    display.attach(&disp, 0.1); // connexion de la fonction périodique aux 1/10 de seconde // roule constamment
+    while (1){     
+    
     }
+    
+}
+