LilyPad-USB CN

来自Duinopeak_COM
跳转至: 导航搜索

产品简介

这个lilypad简单但是能够实现很多的功能...。我们已经更新了以前简单主控板重新创建lilypadUSB,并且用新ATMega32U4取代经典ATMega328。这不仅意味着它能够运行最新和功能强大的引导程序的一个变体,
但这也意味着不再依赖FTDI USB转串口芯片了!你需要的唯一额外硬件方案lilypad USB是一根micro-USB电缆,因为新的芯片内置USB支持。在Arduino IDE版本1.0.2及以上版本,Lilypad USB能够很好的得到正式支持!
LilyPad-USB front.jpg
就像lilypad一样简单,这个主板带有一个JST插槽,所以你可以直接连接锂电池取电和用一个板载电源开关当你觉得电源指示灯不再闪烁的时候,你可以把它关掉。这些主板设计以简化您的下一个可缝纫的项目让事情保持简单的为你腾出更多的工作空间,而不需要缝的电源。该锂电池甚至可以通过主控板来充电,不需要更多的特殊的外部电池充电器!

应用示例

下面的demo演示了怎样来控制LilyPad套件中的每一个PCB有趣的功能。

/* Pin Definitions */
// LEDs: white LEDs are connected to 5, 6, A2, A3, A4
int ledPins[] = {5, 6, A2, A4, A3, 9, 10, 11};
int switchPin = 2;
int buttonPin = A5;
int vibePin = 3;
int buzzerP = 7;
int buzzerN = 12;
int lightSensorPin = A6;
int tempSensorPin = A1;

/* Global variables */
int light = 100;

void setup()
{
  //STARTUP LED SEQUENCE
  for(int i=0; i<5; i++)  // This for loop will run 5 times
  {  // blink the white LEDs (first 5 LEDs in ledPins array)
    pinMode(ledPins[i], OUTPUT);  // set pin as output
    digitalWrite(ledPins[i], HIGH);  // turn LED on
    delay(250);  // wait for a quarter second
    digitalWrite(ledPins[i], LOW); // turn LED off
  }
  for(int i=5;i<8;i++)  // This for loop will run 3 times
  {   // blink the RGB LEDs (last 3 LEDs in ledPins array)
    pinMode(ledPins[i], OUTPUT);   // set the pin as an output 
    digitalWrite(ledPins[i], LOW);  // turn RGB LED on
    delay(250);  // wait a quarter second
    digitalWrite(ledPins[i], HIGH);  // turn the RGB LED off
    // Note that a HIGH turns the RGB LED off, LOW is on
    // that's backwards from the white LEDs
  }
  ////////////////////////////////////////////

  //Switch
  pinMode(switchPin, INPUT);  // set the switch as an input
  digitalWrite(switchPin, HIGH);  // enable the pull-up resistor

  //Button
  pinMode(buttonPin, INPUT);  // set the pin as an input
  digitalWrite(buttonPin, HIGH);  // enable the pull-up resistor

  //VIBE
  pinMode(vibePin, OUTPUT);  // set the pin as an output

  //Buzzer
  pinMode(buzzerP, OUTPUT);  // set both buzzer pins as outputs
  pinMode(buzzerN, OUTPUT);

  Serial.begin(9600);  // We'll output some information over serial
}

void loop()
{
  //Buzzer
  if(digitalRead(buttonPin) == 0)
  {  // if you press the button, make a short buzz
    digitalWrite(buzzerP, HIGH);
    digitalWrite(buzzerN, LOW);
    delay(1);
    digitalWrite(buzzerP, LOW);
    digitalWrite(buzzerN, HIGH);
  }
  else  // If the button is not pressed go in here
  {
    if(digitalRead(switchPin) == 0)
    {  // If the switch is on, vibrate
      digitalWrite(vibePin, HIGH);
      delay(100);
      digitalWrite(vibePin, LOW); 
    }
    
    ///LIGHT TEST
    if(analogRead(lightSensorPin) < 20){
      //if its dark, turn on all white leds...
      for(int i=0;i<5;i++)
      {
        digitalWrite(ledPins[i], HIGH);
      }
    }
    else{
      // if it's light, turn them off...
      for(int i=0;i<5;i++)
      {
        digitalWrite(ledPins[i], LOW);
      }
    }

    ///TEMP TEST 
    if(analogRead(tempSensorPin) > 160)
    {
      //if the tech puts a little hot air over the temp sensor it will raise to at least 170
      digitalWrite(ledPins[5], LOW); //Turn on red LED - to indicate "hot"
    }
    else{
      digitalWrite(ledPins[5], HIGH);  // turn the red LED off
    }
    
    /* from here on down, we'll just print out the status of every input */
    Serial.print("Switch=");
    Serial.print(digitalRead(switchPin));

    Serial.print("  Temp=");
    Serial.print(analogRead(tempSensorPin));
    
    Serial.print("  Button=");
    Serial.print(digitalRead(buttonPin));

    Serial.print("  Light=");
    Serial.println(analogRead(lightSensorPin)); 
  }
}

注意:打开串口并确定ArduinoIDE的波特率是设置在9600。

资源