欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: arduino小車程序 [打印本頁]

作者: shuxin    時間: 2016-11-28 22:57
標題: arduino小車程序
引腳接法:
nRF24L01   Arduino UNO
VCC        <->        3.3V
GND        <->        GND
CE        <->        D9
CSN        <->        D10
MOSI    <->        D11
MISO    <->        D12
SCK        <->        D13
IRQ        <->        不接
*/
#include <SPI.h>                    //24L01庫文件
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int a;
int aa;
int b;
int bb;
int c;
int cc;
int d;
int dd;
void setup()
{
  Mirf.cePin = 9;                    //設置CE引腳為D9
  Mirf.csnPin = 10;                    //設置CEN引腳為D10
  Mirf.spi = &MirfHardwareSpi;      //加載24L01  SPI
  Mirf.init();                      //開始
  Mirf.setTADDR((byte *)"serv2");   //發送到"接收地址"
  Mirf.payload = sizeof(int);       //數據類型(整數)
  Mirf.channel = 3;                 //發送通道,可以填0~128,收發必須一致。
  Mirf.config();                    
  Serial.begin(9600);
}
void loop()
{
  a=analogRead(0);                 //讀取電平(0至1023)
  b=analogRead(1);      
  c=analogRead(2);            
  d=analogRead(3);
  delay(10);
Serial.print(a);
Serial.print("   ");
Serial.print(b);
Serial.print("   ");
Serial.print(c);
Serial.print("   ");
Serial.println(d);
a=map(a,0,1023,0,1023) ;
b=map(b,0,1023,1024,2047) ;
c=map(c,0,1023,2048,3071) ;
d=map(d,0,1023,3072,4095) ;
   if (a !=aa)
   {
     Mirf.send((byte *)&a);       //發送X向電平
     while(Mirf.isSending());     //等待或繼續發送??
     aa=a;
   }
  if (b !=bb)
  {
     Mirf.send((byte *)&b);       //發送X向電平
     while(Mirf.isSending());     //等待或繼續發送??
     bb=b;
  }
  if (c !=cc)
  {
     Mirf.send((byte *)&c);       //發送X向電平
     while(Mirf.isSending());     //等待或繼續發送??
     cc=c;
  }
  if (d !=dd)
  {
     Mirf.send((byte *)&d);       //發送X向電平
     while(Mirf.isSending());     //等待或繼續發送??
     dd=d;
   }
   delay(10);                     // 等待0.01秒
}







歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1