arduino USB

#include <SPI.h>
#include <Adb.h>
 
#define  LEDcount  3
 
Connection * connection;
 
long lastTime;
 
//Array of state of LEDs
uint8_t LEDState[LEDcount];
 
// Event handler for shell connection; called whenever data sent from Android to Microcontroller
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
{
  // In this example Data packets contain three bytes: one for the state of each LED
  if (event == ADB_CONNECTION_RECEIVE)
  {
    int i;
    for (i = 0; i < LEDcount; i++)
    {
      if(LEDState[i] != data[i])
      {
        digitalWrite(i+2, data[i]);   // Change the state of LED
        Serial.println(data[i],DEC);   // Output debugging to serial
        LEDState[i] = data[i];          // Store the State of LED
      }    
    }
  }
}
 
void setup()
{
  int i;
  for (i = 0; i < LEDcount; i++)
  {
    pinMode(i+2,OUTPUT); // Set pins as output
    LEDState[i] = 0; // Init state to 0
  }  
  // Init serial port for debugging
  Serial.begin(57600);
 
  // Init the ADB subsystem.  
  ADB::init();
 
  // Open an ADB stream to the phone's shell. Auto-reconnect. Use any unused port number eg:4568
  connection = ADB::addConnection("tcp:4568", true, adbEventHandler);  
}
 
void loop()
{
  // Poll the ADB subsystem.
  ADB::poll();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值