From a544df63657359056b214bcc20b1266e9c8e623c Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 7 May 2019 10:31:20 +0200 Subject: [PATCH] remove led_builin usage because d13 is used by spi --- .../mixercontroller_w5100.ino | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/controller/mixercontroller_w5100/mixercontroller_w5100.ino b/controller/mixercontroller_w5100/mixercontroller_w5100.ino index cf2b410..d3772a4 100644 --- a/controller/mixercontroller_w5100/mixercontroller_w5100.ino +++ b/controller/mixercontroller_w5100/mixercontroller_w5100.ino @@ -25,9 +25,9 @@ long last_serialdebug=0; #define INTERVAL_SERIALDEBUG 200 //Inputs -#define PIN_BUTTON 9 -#define PIN_ENCA 7 -#define PIN_ENCB 8 +#define PIN_BUTTON 9 //D9 = PB1 +#define PIN_ENCA 7 //D7 = PD7 +#define PIN_ENCB 8 //D8 = PB0 #define BUTTON_RELEASE_DEBOUNCE 100 //minimum time after button release to reenable triggering boolean button_flag=false; //true if button pressed @@ -36,9 +36,9 @@ long last_button_released=0; //last time button has been released (for debounce) //Shift Register 595 //connections: https://www.arduino.cc/en/tutorial/ShiftOut -#define SRLATCH 4 -#define SRCLOCK 5 -#define SRDATA 6 +#define SRLATCH 4 //D4 = PD4 +#define SRCLOCK 5 //D5 = PD5 +#define SRDATA 6 //D6 = PD6 uint16_t srbits=0; #include @@ -49,7 +49,7 @@ float encoderMultiplier=4.0; #define SRPIN_MOTOR_IN1 1 //L293(pin2) Motor IN1 #define SRPIN_MOTOR_IN2 2 //L293(pin7) Motor IN2 -#define PIN_POT A0 //reference potentiometer wiper +#define PIN_POT A0 //A0 = PC0, reference potentiometer wiper #define DEADZONE_POTI 5 //maximum allowed error. stop when reached this zone #define POT_MIN 10 //minimum value pot can reach #define POT_MAX 1010 //maximum value pot can reach @@ -80,9 +80,6 @@ uint8_t error=0; #define MOTORDIDNOTTURN 1 void setup() { - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN,HIGH); - pinMode(PIN_BUTTON,INPUT_PULLUP); pinMode(PIN_POT,INPUT); @@ -208,7 +205,7 @@ void loop() { if (error==0){ //no errors if (!poti_reachedposition && abs(poti_read-poti_set)>DEADZONE_POTI){ //error too high - digitalWrite(LED_BUILTIN,HIGH); + if (poti_read-poti_set < 0){ MOTOR_LEFT(); }else{ @@ -224,7 +221,6 @@ void loop() { Serial.print(" vel="); Serial.println(); poti_reachedposition=true; //position reached - digitalWrite(LED_BUILTIN,LOW); } @@ -292,6 +288,7 @@ void sendData() { } void callback(char* topic, byte* payload, unsigned int length) { + payload[length] = '\0'; //add end of string character Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] ");//MQTT_BROKER @@ -307,6 +304,16 @@ void callback(char* topic, byte* payload, unsigned int length) { if (strncmp((const char*)topic, "audiomixer/main/volume/set",sizeof(topic)) == 0) { //Serial.println("republish"); + + String s = String((char*)payload); + Serial.print("Stringreceived="); + Serial.println(s); + float _floatvalue = s.toFloat(); + Serial.print("setvalue="); + Serial.println(_floatvalue); + + poti_set=constrain(map(_floatvalue,0.0,100.0,POT_MIN,POT_MAX),POT_MIN,POT_MAX); //set new poti position + poti_reachedposition=false; //aim for new position mqttClient.publish("audiomixer/main/volume", payload, length ); }