Go Down

Topic: Control Livolo switches VER:C0 14 pin touch (Read 535 times) previous topic - next topic

GoGs99

Nov 05, 2017, 06:00 pm Last Edit: Nov 05, 2017, 06:39 pm by GoGs99
Purple: +5V
Gray: GND
Yellow: Software switching
Blue: Software switching
Green: +1.3V (arduino map(268))
White: ON / OFF detection (bridged from chip for led)

Source code
Code: [Select]


int milliVolts =0;  //calculate 1.3V
boolean pin11 = false; //Pin output enabled / disabled
boolean setOnOFF = false; // software on/oFF

void setup() {
  pinMode(11, OUTPUT); //Output LED
  pinMode(9, OUTPUT); //Output 1.3V
  pinMode(8, OUTPUT); //Output software switching
  pinMode(7, OUTPUT); //Output software switching

  milliVolts = map(268, 0, 1023, 0, 255); // map val 268 1.3V

  analogWrite(9,milliVolts); //send pin 9 1.3V

  digitalWrite(8,HIGH); //initial positionig for software switching
  digitalWrite(7,LOW); //initial positionig for software switching
  int val = analogRead(0); //read input val //sometimes switch is on
  if(val > 600) //input val of A0 >600
  {
    setOnOFF = true;
    pin11 = true;
    SoftwareOnOFF(false); // if is ON set to OFF
  }
  else
  {
    setOnOFF = false;
    pin11 = false;
    SoftwareOnOFF(false);
  }

  Serial.begin(9600);
}
 
void loop(){

  int val = analogRead(0);  // read input value
  if(val<50 && !pin11) // val < 50 just in case
  {
    pin11 = true;
    fade(0,255,11); // Fade to ON
  }
  else if (val >600 && pin11) // bigger then 600
  {
    pin11 = false;
    fade(255,0,11); // fade to OFF
  }
  if(Serial.available() > 0) // read for serial input 1 or 0
  {
    String valStr = Serial.readStringUntil('\n');
    if(valStr == "1") // if = 1 turn on if is not
    {
      SoftwareOnOFF(true);
    }
    else if(valStr == "0") // if = 0 turn OFF if is ON
    {
      SoftwareOnOFF(false);
    }
  }
  delay (100); // delay
}
void fade(int from, int to, int ledPin)
{
  int initVal = from;
  while (initVal != to)
  {
    if(from > to)
    {
      initVal--;
    }
    else
    {
      initVal++;
    }
 
    analogWrite(ledPin, initVal); // send fade to pin
    delay(3);
  }
}

void SoftwareOnOFF(boolean OnOFF)
{
  if(OnOFF && pin11) return;
  if(!OnOFF && !pin11) return;
  if(setOnOFF)
  {
    digitalWrite(8,LOW);
    digitalWrite(7,HIGH);
  }
  else
  {
    digitalWrite(7,LOW);
    digitalWrite(8,HIGH);
  }
  setOnOFF = !setOnOFF; // just reverse
}




Serial input 1= ON, 0 = OFF

pin 11 = Led output (fade in / out)
pin 9   = ~1.3V
pin 8, 7 = Software livolo led switching
Pin A0 = Detection


I made bridge to 12V pin on livolo from led chip. To use connector for easy use

FULL image size: Gpgoto

Go Up