|  | 
 
 發表於 2018-1-3 01:26:39
|
顯示全部樓層 
| 報告康大~~ 
 我我我~~程式不小心2隻腳寫顛倒~
 應該寫這樣的:           PT6961 LED(PT6961_DIN, PT6961_CLK, PT6961_CS);
 但我寫錯順序成這樣:PT6961 LED(PT6961_CS, PT6961_CLK, PT6961_DIN);
 
 
  uno_100ms_demo.zip
(5.66 KB, 下載次數: 6) 
   底下為 UNO 測試程式。
 底下為硬體接線定義,想寫的話直接寫數字:
 D13 為 mosfet 輸出控制腳(版上這隻腳有一個LED)
 D10 PT6961 CS
 D9  PT6961 CLK
 D8  PT6961 DIN
 D7  enter按鍵
 D6  up 鍵
 D5  down 鍵
 
 
 
 複製代碼#include<arduino.h>
#include "PT6961.h"
#include "Pushbutton.h"
#define OUTPUT_CONTROL 13
#define BUTTON 7
#define KEY_UP 6
#define KEY_DOWN 5
#define PT6961_CS 10
#define PT6961_CLK 9
#define PT6961_DIN 8
#define DELAY_TIME 100 // 100ms
Pushbutton button_enter(BUTTON);
Pushbutton button_up(KEY_UP);
Pushbutton button_down(KEY_DOWN);
//PT6961 LED(PT6961_CS, PT6961_CLK, PT6961_DIN);
PT6961 LED(PT6961_DIN, PT6961_CLK, PT6961_CS);
uint16_t hold_time = DELAY_TIME;
void setup()
{
  pinMode(OUTPUT_CONTROL,OUTPUT);
  LED.initDisplay();
}
void loop()
{
  while(1)
  {
    int count;
    LED.sendNum(hold_time,0);
    while(!button_enter.isPressed()) // check key up/down if no enter key pressed. 
    {
      // process key up pressed
      while(button_up.isPressed() && hold_time < 9990) 
      {
        hold_time+=10;
        LED.sendNum(hold_time,0);
        delay(150); // simple debonce
        if(!button_up.isPressed()) break;      
      }
      // process key down pressed
      while(button_down.isPressed() && hold_time > 10)
      {
         hold_time-=10;
         LED.sendNum(hold_time,0);
         delay(150);
         if(!button_down.isPressed()) break; 
      }
    }
    // trun on
    digitalWrite(OUTPUT_CONTROL,HIGH);
    delay(hold_time);
    digitalWrite(OUTPUT_CONTROL,LOW);
    
    button_enter.waitForRelease();
  }
}
 
 
 
 | 
評分
7
查看全部評分
 |