C++ project

Dependencies:   SeeedGrayOLED mbed

Fork of MBED_CPP_DII4A by Projet C++

Files at this revision

API Documentation at this revision

Comitter:
mr_cub3
Date:
Mon Mar 13 18:25:52 2017 +0000
Parent:
1:e1e7d89e37fe
Commit message:
bastien

Changed in this revision

WeatherClick_I2C.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
temp.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/WeatherClick_I2C.lib	Mon Mar 13 08:35:17 2017 +0000
+++ b/WeatherClick_I2C.lib	Mon Mar 13 18:25:52 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/mr_cub3/code/WeatherClick_I2C/#40e32a6a70f9
+https://developer.mbed.org/teams/mr_cub3/code/WeatherClick_I2C/#86b3283c6b87
--- a/main.cpp	Mon Mar 13 08:35:17 2017 +0000
+++ b/main.cpp	Mon Mar 13 18:25:52 2017 +0000
@@ -7,17 +7,26 @@
 
 int main()
 {
-    //greenPB.mode(PullUp);
-    while(1) {
-        //myLed = greenPB;
-        SeeedGrayOled.init();             //initialize SEEED OLED display
-        SeeedGrayOled.clearDisplay();     //Clear Display.
-        SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
-        SeeedGrayOled.setVerticalMode();  // Set to vertical mode for displaying text
-        SeeedGrayOled.setTextXY(0,0);
-        SeeedGrayOled.setGrayLevel(10);
-        SeeedGrayOled.putString("Coucou Candy");
-        wait_ms(1.0);
+    greenPB.mode(PullUp);
+    while(1) 
+    {
+        
+        
+    
+        myLed = !greenPB;
+    
+        //SeeedGrayOled.init();             //initialize SEEED OLED display
+        //SeeedGrayOled.clearDisplay();     //Clear Display.
+        //SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
+        //SeeedGrayOled.setVerticalMode();  // Set to vertical mode for displaying text
+        //SeeedGrayOled.setTextXY(0,0);
+        //SeeedGrayOled.setGrayLevel(10);
+        //SeeedGrayOled.putString("Coucou Candy");
+        //wait(1);
+    
+        
+        
+        
         //for(char i=1; i < 11 ; i++) {
         //    SeeedGrayOled.setTextXY(i,0);  //set Cursor to first line, 0th column
         //    SeeedGrayOled.setGrayLevel(i); //Set Grayscale level. Any number between 0 - 15.
@@ -25,7 +34,7 @@
         //    wait_ms(1.0);
         //}
 
-        wait(5.0);
+        //wait(1.0);
     }
 
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/temp.cpp	Mon Mar 13 18:25:52 2017 +0000
@@ -0,0 +1,132 @@
+/*
+ * SeeedGrayOLED.cpp
+ * SSD1327 Gray OLED Driver Library for SSD1327
+ *
+ * Copyright (c) 2011 seeed technology inc.
+ * Author        :   Visweswara R
+ * Create Time   :   Dec 2011
+ * Change Log    :
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "mbed.h"
+#include "TouchClamp.h"
+#include "I2C.h"
+#include <stdio.h>
+#include <string.h>
+
+// 8x8 Font ASCII 32 - 127 Implemented
+// Users can modify this to support more characters(glyphs)
+// BasicFont is placed in code memory.
+
+// This font can be freely used without any restriction(It is placed in public domain)
+// const unsigned char BasicFont[][8] PROGMEM=
+
+TouchClamp::TouchClamp(PinName sda, PinName scl,int addr):
+    _device(sda, scl)
+{    
+    _addr = addr;
+}
+
+void TouchClamp::init(void)
+{
+    unsigned char mpr[3]={_addr,0x5E,0x00};
+    int ack = 0;
+    int i = 0;
+    // Put the MPR into setup mode
+    ack = write(mpr,3);
+    
+    // Electrode filters for when data is > baseline
+    unsigned char elec_flt[6]={_addr,0x2B,0x01,0x01,0x00,0x00};
+    ack = write(elec_flt,6);
+    
+    // Electrode filters for when data is < baseline
+    unsigned char elec_flt2[6]={_addr,0x2F,0x01,0x01,0x00,0x00};
+    ack = write(elec_flt2,6);
+        
+    // Electrode touch and release thresholds
+    for(i=0; i<12; i++){
+        _device.start();
+        ack = _device.write(_addr);
+        ack = _device.write(0x41+(i*2));
+        ack = _device.write(0x0F);
+        ack = _device.write(0x0A);
+        _device.stop();
+    }   
+ 
+    // Proximity Settings
+    unsigned char proximy[13]={_addr,0x36,0xff,0xff,0x00,0x00,0x01,0x01,0xff,0xff,0x00,0x00,0x00};
+    ack = write(proximy,13);
+ 
+    unsigned char proximy2[4]={_addr,0x59,0x5D,0x02};
+    ack = write(proximy2,4);
+    
+    unsigned char proximy3[3]={_addr,0x5D,0x04};
+    ack = write(proximy3,3);
+    
+    unsigned char proximy4[3]={_addr,0x5E,0x0C};
+    ack = write(proximy4,3); 
+}
+
+int TouchClamp::write(unsigned char * data, int size)
+{
+        int i = 0;
+        int ack = 0;
+        /////////////////////
+        ///WRITE PROTOCOLE///
+        /////////////////////
+        _device.start();
+        ack = _device.write(_addr); 
+        for(i=0;i<size;i++)
+        {
+            ack = _device.write(data[i]);
+            if(ack == 0)
+                return 0;
+        }
+        _device.stop();
+        return 1;
+}
+
+unsigned char TouchClamp::readTouch(unsigned char command)
+{
+        unsigned char result = 0;
+        int ack = 0;        ////////////////////
+        ///READ PROTOCOLE///
+        ////////////////////
+        //Start the command
+        _device.start();
+        // Address the target (Write mode)
+        ack = _device.write(_addr);
+        if(ack == 0)
+                return 0;
+        // Re-send the target address in read mode
+        ack = _device.write(command);
+        if(ack == 0)
+                return 0;
+        // Re-start for read of data
+        _device.start();
+        // Re-send the target address in read mode
+        ack = _device.write(_addr+1);
+        if(ack == 0)
+                return 0;
+        // Read in the result
+        result = _device.read(0);
+        // Reset the bus        
+        _device.stop();
+        
+        return result;
+}
+