2017年10月18日 星期三

使用Linkit 7697打造遠端遙控智能燈座 - Part 2

這次手作了35 PCS課堂上使用,包括11Maker Faire Taipei展覽樣品



和鎢絲燈泡一起打包過後,就像準備出貨,只是難看了點



工作桌凌亂不堪,但為了就是要學員一次就上手!

且準備了九支程式、電路圖說明與Layout走線,要在三小時完全學會

而且當天會有小鮮肉助教,把教材給他之後,我就可以喝飲料看漫畫了

希望之後完整系列課程結束,能讓大家多多關心自己家中的長輩 ^ ^



先前寫了一篇使用Linkit 7697打造遠端遙控智能燈座,這一篇是Part 2

以下程式可以按下dab調光


int pinLed = 14;
int PWM = 9; // PWM pin
int dimming = 40;  // Dimming level (0-128)  0 = ON, 128 = OFF
int flag1=0,flag2=0,flag3=0;

void setup(){
    Serial.begin(9600);
    pinMode(2, INPUT);
    pinMode(pinLed, OUTPUT);
    analogWrite(PWM, 55);  //setting PWM speed
    Serial.println("Hello");
}

void loop(){
   int switchStatus = digitalRead(2);
    String s = "";
 
    while (Serial.available()) {
    char c = (char) Serial.read();
        if(c!='\n')
        {
            s += c;
        }
        delay(1); 
    }

    if(s=="d"){
    flag1=1;
    flag2=0;
    flag3=0;
    dimming=40;
    Serial.println(s);
 }
    if(s=="a"){
     flag2=1;
     flag1=0;
     flag3=0;
     dimming=30;
     Serial.println(s);
 }

 if(s=="b"){
     flag3=1;
     flag2=0;
     flag1=0;
     Serial.println(s);
 }

   if(switchStatus==HIGH && flag1==1)
  {
   
   Serial.println("ddd");
  int dimtime = (65*dimming);    // For 60Hz =>65   
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC   
  digitalWrite(pinLed , HIGH);   // Fire the TRIAC
  delayMicroseconds(8.33);         // triac On propogation delay
         // (for 60Hz use 8.33) Some Triacs need a longer period
  digitalWrite(pinLed, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
     }

     if(switchStatus==HIGH && flag2==1)
  {
   
  Serial.println("aaa");
  int dimtime = (65*dimming);    // For 60Hz =>65   
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC   
  digitalWrite(pinLed , HIGH);   // Fire the TRIAC
  delayMicroseconds(8.33);         // triac On propogation delay
         // (for 60Hz use 8.33) Some Triacs need a longer period
  digitalWrite(pinLed, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC

  }

  if(switchStatus==HIGH && flag3==1)
  {
   
  Serial.println("bbb");
  digitalWrite(pinLed, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC

  }
}

以下程式可做出AC呼吸燈泡模式

將%Localappdata%\Arduino15\packages\LinkIt\hardware\linkit_rtos\0.8.4\cores\arduino\wiring_interrupt.c

裡面的eint_config.debounce_time = 50; // debounce time unit: ms

50改為0


-->可以在C槽中找












int pinLed = 14; //output pin
int flag = 0;
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
int brightness = 40;    // how bright the LED is
int fadeAmount = 1;    // how many points to fade the LED by

void setup()
{
 pinMode(pinLed, OUTPUT);
 attachInterrupt(2, interrupt, RISING); //using interrupt
 Serial.begin(9600);
}

void loop()
{
if (flag == 1 )
{
// change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;
 dimming=brightness;
 Serial.println(brightness);
 int dimtime = (65*dimming);    // For 60Hz =>65   
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC   
  digitalWrite(pinLed, HIGH);   // Fire the TRIAC
  delayMicroseconds(8.33);         // triac On propogation delay
         // (for 60Hz use 8.33) Some Triacs need a longer period
  digitalWrite(pinLed, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
      // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 10 || brightness >= 100)
  {
    fadeAmount = -fadeAmount;
  }
   flag = 0;
  }
}

void interrupt()
{
 flag = 1;
}

這次是初階課程,如果控制30顆燈泡同時閃爍或亮滅,會挺壯觀

但可惜的是,MQTT要等到進階課程才會教到  ^ ^

加入我們吧!

沒有留言:

張貼留言

FB設定搶先看的方式

設定搶先看的兩種方式 A1. 先到我家的日常粉絲團按下 …( 紅框處 ) A2. 按下追蹤中 ( 紅框處 ) A3. 按下搶先看 ( 紅框處 ) A4. 完成!!! 另一種方式 ...