瀏覽代碼

ad5242 handling first version

added wire declaration, setup
Etienne Landon 8 年之前
父節點
當前提交
4e76619cce
共有 2 個文件被更改,包括 38 次插入11 次删除
  1. 34 0
      AD5242.h
  2. 4 11
      tens_esp.ino

+ 34 - 0
AD5242.h

@@ -0,0 +1,34 @@
+#include <Wire.h>
+
+#define AD_adress1 0x2c
+#define AD_adress2 0x2f
+#define AD_pot1 0x00
+#define AD_pot2 0x80
+
+int potValue[4];
+int potValueUpdate[4];
+byte potAdress[][2] = { {AD_adress1, AD_pot1},
+                       {AD_adress1, AD_pot2},
+                       {AD_adress2, AD_pot1},
+                       {AD_adress2, AD_pot2}, };
+
+void setup_AD5242() {
+  Wire.begin(); // join i2c bus (address optional for master)
+  Serial.begin(115200);
+}
+
+void handle_AD5242() {
+  for (int i ; i++ ; i<4){
+    if (potValue[i] != potValueUpdate[i]) {
+      potValue[i] = potValueUpdate[i];
+      Wire.beginTransmission(potAdress[i][1]);
+      Wire.write(potAdress[i][2]);
+      Wire.write(potValue[i]); 
+      Wire.endTransmission();
+      Serial.print(potAdress[i][1] + " : ");
+      Serial.println(potAdress[i][2]);
+    }
+  }
+  
+}
+

+ 4 - 11
tens_esp.ino

@@ -12,16 +12,11 @@
 
 #include <Ticker.h>
 
-
-
-
-
 #include "leds.h"     //config and functions relative to leds
 #include "ota.h"      //config and functions relative to ota firmware updates
 #include "wifimgr.h"   //config and functions relative to wifi and access point configuration and configuration permanent saving
 #include "osc.h"  //some helpers functions
-
-
+#include "AD5242.h" //
 
 
 void setup ( void ) {
@@ -29,14 +24,12 @@ void setup ( void ) {
   delay(500) ;
   Serial.begin(115200);
   Serial.println("Starting ESP8266");
-
+  setup_AD5242() ;
   setupLeds();
-  
   setupWifi(); 
-
   setup_OSC() ;
-  
   setupOTA();
+  
  
   blueLedState(-1, 500);
   
@@ -49,7 +42,7 @@ void loop ( void ) {
   StartConfigAP();
   checkOTA();
   handle_OSC();
-
+  handle_AD5242();
   
 }