DataAquisitieMisan3

Dependencies:   LM75B MMA7660 Servo mbed

Fork of DataAquisitieMisan by Michiel Van Endert

Revision:
1:2b6bdf677573
Parent:
0:e4782112c3fd
Child:
2:b3eddbd12635
--- a/main.cpp	Tue Apr 28 11:41:25 2015 +0000
+++ b/main.cpp	Mon May 18 20:04:55 2015 +0000
@@ -1,39 +1,353 @@
 #include "mbed.h"
 #include "SerialRPCInterface.h"
-SerialRPCInterface SerialInterface(USBTX, USBRX);
-float ai1=0;
-float ai2=0;
+#include "LM75B.h"
+#include "C12832.h"
+#include "MMA7660.h"
+#include <time.h>
+#include <stdlib.h>
+#include "Servo.h"
+
+//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  
+//  //  //  //  //  //  //* Pennen defineren voor libs  */  //  //  //  //  //                  
+C12832 glcd(p5, p7, p6, p8, p11);                       //Grafische display aangesloten op P5,6,7,8,11
+MMA7660 MMA(p28, p27);                                  //I2C Accelerometer
+LM75B LM75(p28,p27);                                    //LM75 Temp Sensor
+SerialRPCInterface SerialInterface(USBTX, USBRX);       //USB seriele communicatie opzetten
+
+PwmOut r (p23);                                         //RGB Led op pen 23-25
+PwmOut g (p24);   
+PwmOut b (p25);   
+DigitalIn up(p15);                                      //Joystick aangesloten op P12-16
+DigitalIn down(p12);
+DigitalIn left(p13);
+DigitalIn right(p16);
+DigitalIn fire(p14);                                    //Drukknop joystick zit op pen P14
+
+DigitalOut connectionLed(LED1);                         //Accel OK LED
+
+BusOut leds(LED1,LED2,LED3,LED4);                       //Leds op MBED zelf defineren
+
+//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  
+//  //  //  //  //  //  //*Variabelen aanmaken  */  //  //  //  //  //  //  //
+float potentiometer1 = 0;
+float potentiometer2 = 0;
+float Xaxis = 0;
+float Yaxis = 0;
+float Zaxis = 0;
+
+int modus = 0;
 int alarm1 = 0;
 int alarm2 = 0;
-RPCVariable<float> rpc_ai1(&ai1,"ai1");
+int kleur = 0;
+int rood = 0;
+int groen = 0;
+int blauw = 0;
+
+char orientation;
+char side;
 
-RPCVariable<float> rpc_ai2(&ai2,"ai2");
- 
+char Left;
+char Right;
+char Down;
+char Up;
+char Front;
+char Back;
+
+
+RPCVariable<float> rpc_ai1(&potentiometer1,"potentiometer1");
+RPCVariable<float> rpc_ai2(&potentiometer2,"potentiometer2");
 RPCVariable<int> rpc_alarm1(&alarm1,"alarm1");
 RPCVariable<int> rpc_alarm2(&alarm2,"alarm2");
+
 AnalogIn pot2(p19);
+AnalogIn pot1(p20);
+
 DigitalOut led(LED1);
-AnalogIn pot1(p20);
 DigitalOut led2(LED2);
 
- 
+DigitalIn enter(p14);
+
+PwmOut speaker(p26);
+PwmOut Zaxis_p(p23);
+PwmOut Zaxis_n(p24);
+
+Servo Servo1(p21);
+Servo Servo2(p22);
+
+void RGB_routine();
+void ReadPot();
+void Accelero();
+void Servosturing();
+
+//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  
+//  //  //  //  //  //  //*Begin van het hoofdprogramma */  //  //  //  //  //  
 int main() {
+
+    speaker.period(0.5);    
+    r.period(0.001);
+    g.period(0.001);
+    b.period(0.001);
+    
+            
+    glcd.cls();                                      //Clear het display
+    glcd.locate(0,3);                                //Zet de cursor op X = 0 & Y = 3
+    glcd.printf("Project Misan");                    //Zet "Project Misan" op het LCD
+    wait(1);                                         //Wacht 1 seconde
+    glcd.printf("Use the joystick");                //Zet "Project Misan" op het LCD
+   
     while (1){
-        ai1 = pot2;
-        ai2 = pot1;
-        if(pot2 > 0.3) {
-            led = 1;
-            alarm1 = led;
-        } else {
-            led = 0;
-            alarm1 = led;
+
+        if (fire)
+        {
+            while(fire){}
+            modus = modus++;
+            speaker = 0.5;      
+        }
+        
+        switch (modus) 
+        {
+                //RGB Controller
+                case 0: 
+                    glcd.cls();                                      //Clear het display
+                    glcd.locate(0,0);                                //Zet de cursor op X = 0 & Y = 0
+                    glcd.printf("RGB Led controller");
+                    RGB_routine();
+                break;
+                
+                //ADC Potentiometer
+                case 1:
+                    glcd.cls();                                      //Clear het display
+                    glcd.locate(0,0);                   
+                    glcd.printf("Read Potentiometers");
+                    ReadPot();
+                break;    
+                
+                //Accelerometer MMA7660
+                case 2:
+                    glcd.cls();                                      //Clear het display
+                    glcd.locate(0,0);         
+                    glcd.printf("MMM7660");
+                    glcd.locate(0,10);         
+                    glcd.printf("Accelerometer");                    
+                    Accelero();
+                break;  
+                
+                case 3:
+                    glcd.cls();                                      //Clear het display
+                    glcd.locate(0,0);         
+                    glcd.printf("Servo");         
+                    Servosturing();
+                break;                                             
+        }
+    }
+}
+
+
+
+
+//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //
+//  //  //  //  //  //  //* RGB routine voor kleurwijzigen met de Joystick  */  //  //  //  //  //
+void RGB_routine()
+{
+    if (up)
+    {
+        switch (kleur)
+        {
+            case 0:
+                r = 1.0 - (rood += 0.05);
+                break;
+            case 1:
+                g = 1.0 - (groen += 0.05);
+                break;
+            case 2:
+                b = 1.0 - (blauw += 0.05);
+                break;                                           
         }
-        if(pot1 > 0.7) {
-            led2 = 1;
-            alarm2 = led2;
-        } else {
-            led2 = 0;
-            alarm2 = led2;
-        }    
+        
+    }
+    
+    if (down)
+    {
+        switch (kleur)
+        {
+            case 0:
+                r = 1.0 - (rood -= 0.05);
+                break;
+            case 1:
+                g = 1.0 - (groen -= 0.05);
+                break;
+            case 2:
+                b = 1.0 - (blauw -= 0.05);
+                break;                                           
+        }            
+    }
+    
+    if (right)
+    {
+        switch (kleur)
+        {
+            case 0:
+                kleur += 1;
+                break;
+            case 1:
+                kleur += 1;
+                break;
+            case 2:
+                kleur = 0;
+                break;                                         
+        }  
+        
     }
-}
\ No newline at end of file
+    
+    if (left)
+    {
+        switch (kleur)
+        {
+            case 0:
+                kleur = 2;
+                break;
+            case 1:
+                kleur -= 1;
+                break;
+            case 2:
+                kleur -= 1;
+                break;                                         
+        }  
+        
+    }            
+}
+
+//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //
+//  //  //  //  //  //  //* Inlezen en visualiseren van de potentiometers   */  //  //  //  //  //
+void ReadPot()
+{
+    potentiometer1 = pot1;       //steek de waarde van de Potentiometer1 in ai1
+    potentiometer2 = pot2;       //steek de waarde van de Potentiometer2 in ai2
+    
+    glcd.cls();
+    glcd.locate(0,0);                            //Zet de cursor op X = 0 & Y = 0
+    glcd.printf("Pot 1: %f ", potentiometer1);              //Print de waarde van de potententiometer 1 op het display
+    glcd.locate(0,10);                           //Zet de cursor op X = 0 & Y = 10
+    glcd.printf("Pot 2: %f ", potentiometer2);              //Print de waarde van de potententiometer 2 op het display  
+}
+
+
+void Accelero()
+{
+    if (MMA.testConnection())
+    {
+         leds = 1;
+    }    
+    
+    Xaxis = MMA.x();
+    Yaxis = MMA.y();
+    Zaxis = MMA.z();
+    
+    glcd.cls();
+    glcd.locate(0,0);                            //Zet de cursor op X = 0 & Y = 0
+    glcd.printf("X-Axis: %f G", Xaxis);
+    glcd.locate(0,9);                            //Zet de cursor op X = 0 & Y = 10    
+    glcd.printf("Y-Axis: %f G", Yaxis);
+    glcd.locate(0,18);                           //Zet de cursor op X = 0 & Y = 18      
+    glcd.printf("Z-Axis: %f G", Zaxis);
+    wait(1);      
+    
+    orientation = MMA.getOrientation();
+    side = MMA.getSide();
+    
+    glcd.locate(0,27);                            //Zet de cursor op X = 0 & Y = 0
+    glcd.printf("Side: %s Orientation: %s", side, orientation);    
+} 
+
+
+void Servosturing()
+{
+    
+    potentiometer1 = pot1;       //steek de waarde van de Potentiometer1 in ai1
+    potentiometer2 = pot2;       //steek de waarde van de Potentiometer2 in ai2      
+    wait(0.1);
+    
+    Servo1 = potentiometer1;
+    Servo2 = potentiometer2;
+    
+    glcd.cls();
+    glcd.locate(0,0);                            //Zet de cursor op X = 0 & Y = 0
+    glcd.printf("Servo-1: %f", Servo1);
+    glcd.locate(0,10);                            //Zet de cursor op X = 0 & Y = 10    
+    glcd.printf("Servo-1: %f", Servo2);
+
+    wait(1);     
+} 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    /*switch (side)
+    {        
+        case "Front":        
+            switch (orientation)
+            {
+                case "Left":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Front Left");
+                    break;
+                
+                case "Right":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Front Right");
+                    break;
+                
+                case "Down":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Front Down");
+                    break;      
+                
+                case "Up":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Front Up");
+                    break;                                                      
+            }  
+        break;
+
+    
+        case "Back":        
+            switch (orientation)
+            {
+                case "Left":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Back Left");
+                    break;
+                
+                case "Right":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Back Right");
+                    break;
+                
+                case "Down":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Back Down");
+                    break;      
+                
+                case "Up":
+                    glcd.locate(0,27);               //Zet de cursor op X = 0 & Y = 10      
+                    glcd.printf("Back Up");
+                    break;                                                      
+            }
+        break; 
+    } */              
+