-13%

CJMCU ATtiny85 微型單片機開發板

NT$219 NT$190 未稅

尚有庫存

貨號: 24718531(B3-3) 分類: , 標籤: , , ,
  • 商品說明

商品說明

CJMCU ATtiny85 微型單片機開發板  ATtiny85 微型單片機 arduino 穿戴裝置開發板系列

愛特梅爾公司(Atmel Corporation) 宣布其低功耗的ATtiny 10/20/40微控制器(MCU) 系列,針對按鍵、滑塊和滑輪等觸控感應應用予以優化。這些器件包括了AVR MCU 及其專利的低功耗picoPower技術,是對成本敏感的工業和消費電子市場上多種應用,如汽車控制板、LCD電視和顯示器、筆記本電腦、手機等的理想選擇。

ATtiny MCU系列介紹

愛特梅爾ATtiny 新型單片機集成有愛特梅爾的AVR 微控制器,以及包括1KB至4KB 的閃存,帶有32 KB至256 KB 的SRAM。此外,這些器件支持SPI 和TWI (具備I2C-兼容性) 通信,提供最高靈活性和1.8V至5.5V的工作電壓。ATtinyAVR使用愛特梅爾專利的picoPower技術,耗電極低。通過軟件控制系統時鐘頻率,取得系統性能與耗電之間的最佳平衡,同時也得到了廣泛應用。

https://github.com/sparkfun/LilyTiny_LilyTwinkle

Arduino 範例碼

/******************************************************************************
  LilyTiny (ATtiny85, internal 8 MHz clock)
  Emily Lovell
 
  Controls the behavior of up to four LEDs, depending on pin:
    Pin 0: fades in and out
    Pin 1: heartbeat
    Pin 2: blinks on and off
    Pin 3: twinkles randomly
******************************************************************************/

// Constant definitions
#define maxBrightness 255.0

#define maxTimeOn 9999 
#define blinkTime 125 

// Variables and constants for fading pin. Needs to be a pin with PWM hardware
//  available; on the Tiny85 that's pin 0 and pin 1 only.
#define fadePin 	0  			// Redefine the pin name to something
								//  application specific.
int fadeDirection 	= 1; 		// 1 is brighter, -1 is dimmer
int fadeStep 		= 1; 
int fadeBrightness 	= 1; 

// Variables and constants for fading pin. Needs to be a hardware PWM pin; on
//  Tiny85 that's pin 0 and pin 1 only.
#define HEARTPIN	1 			// Redefine the pin name to something
								//  application specific.
int heartStage = 0;
float heartBrightness = 0;
float heartCounter = 0;

// variables for blink pin (pin 2)
int blinkPin = 2; 
int blinkDelay = blinkTime;
int blinkState = false;

// variables for twinkle pin (pin 3)
int twinklePin = 3; 
int timeOn = 0;
float currentBrightness = 0;
int targetBrightness = 0;
float timeToBright = 0;
float stepToBright = 0;


void setup()
{
  pinMode(twinklePin, OUTPUT);
  startOver();
  pinMode(blinkPin, OUTPUT);
}

void loop()
{
  // calculate brightness for twinkle pin (determined 
  // by how much time the LED is on vs. off) 
  timeOn = calcTimeOn(currentBrightness);
  digitalWrite(twinklePin, HIGH);
  delayMicroseconds(timeOn + 1);
  digitalWrite(twinklePin, LOW);
  delayMicroseconds(maxTimeOn - timeOn);

  // recalculate brightness for twinkle pin
  currentBrightness += stepToBright;
  timeToBright--;
  if(timeToBright == 0)
    startOver();
 
  // calculate brightness for heartbeat pin (by cycling 
  // through phases of pulse pattern)
  heartCounter++;
  if (heartCounter > 144) {
    heartStage = (heartStage + 1) % 4;
    heartCounter = 0;
  }
  else {
    switch(heartStage) {
      case 0:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/12.0;
        heartBrightness += 255/12.0;
        if (heartBrightness > 255)
          heartBrightness = 255;
        break;
      case 1:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/24.0;
        heartBrightness -= 255/24.0;
        if (heartBrightness < 0)
          heartBrightness = 0;
        break;
      case 2:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/12.0;
        heartBrightness += 255/12.0;
        if (heartBrightness > 255)
          heartBrightness = 255;
        break;
      case 3:
        analogWrite(HEARTPIN, heartBrightness);
        heartCounter += 144/72.0;
        heartBrightness -= 255/72.0;
        if (heartBrightness < 0)
          heartBrightness = 0;
        break;
    }
  }
    
 
  // drive blink pin high or low, depending on how much time has passed
  blinkDelay--;
  if (blinkDelay == 0) {
    blinkDelay = blinkTime;
    blinkState = !blinkState;
    digitalWrite(blinkPin, blinkState);
  }  
  
  // increase/decrease brightness of fade pin in steady incremental steps
  analogWrite(fadePin, fadeBrightness);
  fadeBrightness += fadeStep * fadeDirection;
  if (fadeBrightness >= 255) {
    fadeBrightness = 255;
    fadeDirection = -1;
  }
  if (fadeBrightness <= 0) {
    fadeBrightness = 0;
    fadeDirection = 1; 
  }
}

// calculate ratio of time LED is on/off to acheive particular brightness
int calcTimeOn(int desiredBrightness) {
  return desiredBrightness / maxBrightness * maxTimeOn;
}


// restart a new twinkle 
void startOver(){
  if (random(0, 1) == 1)
    targetBrightness = currentBrightness + random(100, 200);
  else
    targetBrightness = currentBrightness - random(100, 200);
  if (targetBrightness < 0)
    targetBrightness = maxBrightness + targetBrightness;
  targetBrightness %= (int)maxBrightness;
  timeToBright = random(10, 30); 
  stepToBright = (targetBrightness - currentBrightness) / timeToBright;
}