五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

丐版3通道帶屏體感遙控器制作

2023-10-04 12:23 作者:暖風(fēng)新葉柳  | 我要投稿

僅供學(xué)習(xí)使用,請(qǐng)勿用于飛行,否則失控炸機(jī)后果自負(fù)。。。

https://www.bilibili.com/video/BV1n8411C7We/?vd_source=0f4ae06f18a4b63b55bb17a7500b26e3

老外的開源程序,經(jīng)過刪減和修改,使用JY-61等模塊制作。

遙控器可接一個(gè)0.91inch OLED屏,顯示出3軸歐拉角。

接收機(jī)可帶3個(gè)舵機(jī)。


遙控器:

#include <SPI.h> // 加載SPI庫(kù)

#include <Wire.h>

#include <JY901.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <nRF24L01.h>? ? ? ? ? ? ? ? ? ? ?//使用NRF24L01需要用到的庫(kù)

#include <RF24.h>? ? ? ? ?

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define OLED_RESET? ? ?-1 // Reset pin # (or -1 if sharing Arduino reset pin)

#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define CE_pin 7? ? ? ? ? ? ? ? ? ? ? ? ? //NRF24L01 CE引腳連接10號(hào)引腳(RFnano舊版)D7(RFnano V3)

#define CSN_pin 8? ? ? ? ? ? ? ? ? ? ? ? ?//NRF24L01 CSN引腳接9號(hào)引腳(RFnano舊版)D8(RFnano V3)

/////////////////////

float anglex, angley, anglez;

float accx, accy, accz;

float wx, wy, wz;

float accx0, accy0, accz0;

float anglex0, angley0, anglez0;

float wx0, wy0, wz0;

float accAngleX, accAngleY;

float gyrodriftx,gyrodrifty,gyrodriftz;

float elapsedTime, currentTime, previousTime;

int i=1;

struct Data_Package {

? byte j1PotX;//byte

? byte j1PotY;

? byte j1PotZ;

};

Data_Package data; //Create a variable with the above structure

const byte addresses[][6] = {"00001", "00002"};? //NRF24L01地址


RF24 radio(CE_pin, CSN_pin);? ? ? ? ? ? ? //配置NRF24L01 CE和CSN引腳

///////////////////////

void setup()?

{

??

? ?Serial.begin(115200);

? ?radio.begin();? ? ? ? ? ? ? ? ? ? ? ? ? //開啟NRF24L01通信

? ?radio.openWritingPipe(addresses[1]);? ? //規(guī)定NRF24L01地址,發(fā)送端和接收端設(shè)置相同的地址,并以此方式啟用兩個(gè)模塊之間的通信。

? ?radio.setPALevel(RF24_PA_MAX);? ? ? ? ? //設(shè)置功率放大器電平

? ?radio.stopListening();? ? ? ? ? ? ? ? ? //停止NRF24L01的接收,作為發(fā)送端

? ?delay(10);

? ??

? ?display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

? ?display.clearDisplay();

? ?while (Serial.available())?

? {

? ? JY901.CopeSerialData(Serial.read()); //Call JY901 data cope function

? }?

? ? delay(2000);??

?for (i=1;i<=50;i+=1)

? {

? ? accx0=(float)JY901.stcAcc.a[0]/32768*16+accx0;

? ? accy0=(float)JY901.stcAcc.a[1]/32768*16+accy0;

? ? accz0=(float)JY901.stcAcc.a[2]/32768*16+accz0;

? ? anglex0=(float)JY901.stcAngle.Angle[0]/32768*180+anglex0;

? ? angley0=(float)JY901.stcAngle.Angle[1]/32768*180+angley0;

? ? anglez0=(float)JY901.stcAngle.Angle[2]/32768*180+anglez0;

? ? wx0=(float)JY901.stcGyro.w[0]/32768*2000;

? ? wy0=(float)JY901.stcGyro.w[1]/32768*2000;

? ? wz0=(float)JY901.stcGyro.w[2]/32768*2000;??

? ? ?delay(50);

? }

? ?accx0=accx0/50;

? ?accy0=accy0/50;

? ?accz0=accz0/50;

? ?anglex0=anglex0/50;

? ?angley0=angley0/50;

? ?anglez0=anglez0/50;

? ?display.setTextSize(1.2); // Draw 2X-scale text 2倍字體

? ?display.setTextColor(SSD1306_WHITE);

? ?display.setCursor(0, 0); //顯示的坐標(biāo)位置

? ?display.print("drift wx:");

? ?display.println(wx0);

? ?display.print("drift wy:");

? ?display.println(wy0);?

? ?display.print("drift wz:");

? ?display.println(wz0);?

? ?display.display();

? ?delay(3000);

? ?display.clearDisplay();

}


void loop()?

{

? accx=(float)JY901.stcAcc.a[0]/32768*16-accx0;

? accy=(float)JY901.stcAcc.a[1]/32768*16-accy0;

? accz=(float)JY901.stcAcc.a[2]/32768*16-accz0;

?

? wx=(float)JY901.stcGyro.w[0]/32768*2000-wx0;

? wy=(float)JY901.stcGyro.w[1]/32768*2000-wy0;

? wz=(float)JY901.stcGyro.w[2]/32768*2000-wz0;


? previousTime = currentTime;? ? ? ? // Previous time is stored before the actual time read

? currentTime = millis();? ? ? ? ? ? // Current time actual time read

? elapsedTime = (currentTime - previousTime) / 1000;? ?// Divide by 1000 to get seconds

? gyrodriftx = wx0 * elapsedTime;

? gyrodrifty = wy0 * elapsedTime;

? gyrodriftz = wz0 * elapsedTime;

?

? anglex=(float)JY901.stcAngle.Angle[0]/32768*180-anglex0;

? angley=(float)JY901.stcAngle.Angle[1]/32768*180-angley0;

? anglez=(float)JY901.stcAngle.Angle[2]/32768*180-anglez0;

? if (anglez<=-180)

? {anglez=360+anglez;}

? accAngleX = (-atan(accy / sqrt(pow(accx, 2) + pow(accz, 2))) * 180 / PI) ;

? accAngleY = (atan(accx / sqrt(pow(accy, 2) + pow(accz, 2))) * 180 / PI);

? anglex=(anglex +? gyrodriftx)*0.98 + 0.02 * accAngleX;

? angley=(angley +? gyrodrifty)*0.98 + 0.02 * accAngleY;

? anglez= anglez +? gyrodriftz;

? display.clearDisplay();

? display.setTextSize(1.2); // Draw 2X-scale text 2倍字體

? display.setTextColor(SSD1306_WHITE);

? display.setCursor(0, 0); //顯示的坐標(biāo)位置

? display.print("GY:");

? display.print(wx);

? display.print(",");

? display.print(wy);

? display.print(",");

? display.println(wz);? ? ?

? display.print("AC:");

? display.print(accx);

? display.print(",");

? display.print(accy);

? display.print(",");

? display.println(accz);

? display.print("Angle:");

? display.print(anglex);

? display.print(",");

? display.print(angley);

? display.print(",");

? display.println(anglez);

? display.display();??

??


? if (anglex<-90){anglex=-90;

? }

? if (anglex>90){anglex=90;}?

? if (anglez<-90){anglez=-90;}

? if (anglez>90){anglez=90;}?


? data.j1PotX = map(anglex, -100, +100, 0, 255);

? data.j1PotY = map(angley, -100, +100, 0, 255);

? data.j1PotZ = map(anglez, -120, +120, 0, 255);

? radio.write(&data, sizeof(Data_Package));? ? ? ? ? //radio.write()函數(shù),將消息發(fā)送給接收器,第一個(gè)參數(shù)是想要發(fā)送的變量,通過在變量名之前使用“&”,設(shè)置一個(gè)指針用于存儲(chǔ)我們想要發(fā)送的數(shù)據(jù)的變量,第二個(gè)參數(shù)設(shè)置了我們想要從該變量中獲取的字節(jié)數(shù)。

? //radio.write(&anglez, sizeof(anglez));? ?

}



/*

? SerialEvent occurs whenever a new data comes in the

?hardware serial RX.? This routine is run between each

?time loop() runs, so using delay inside loop can delay

?response.? Multiple bytes of data may be available.

?*/

void serialEvent()?

{

? while (Serial.available())?

? {

? ? JY901.CopeSerialData(Serial.read()); //Call JY901 data cope function

? }

}


接收機(jī):

/*

? ?Arduino RC Airplane

? ?== Receiver Code =

? by Dejan, www.HowToMechatronics.com

? Library: TMRh20/RF24, https://github.com/tmrh20/RF24/

*/

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>

#include <Servo.h>



RF24 radio(7, 8);? ?// nRF24L01 (CE, CSN)

const byte addresses[][6] = {"00001", "00002"};

unsigned long lastReceiveTime = 0;

unsigned long currentTime = 0;


Servo rudderServo;

Servo elevatorServo;

Servo aileron1Servo;


int rudderValue, elevatorValue, aileron1Value;

// Max size of this struct is 32 bytes - NRF24L01 buffer limit

struct Data_Package {

? byte j1PotX;

? byte j1PotY;

? byte j1PotZ;

};

Data_Package data; //Create a variable with the above structure

void setup() {

? Serial.begin(9600);

? radio.begin();

? radio.openReadingPipe(1, addresses[1]);??

? radio.setPALevel(RF24_PA_MAX);

? radio.startListening(); //? Set the module as receiver

? resetData();?

? rudderServo.attach(6);? ?// CH1

? elevatorServo.attach(5); // CH2

? aileron1Servo.attach(4); // CH3


}

void loop() {

? // Check whether we keep receving data, or we have a connection between the two modules

? currentTime = millis();

? if ( currentTime - lastReceiveTime > 1000 ) { // If current time is more then 1 second since we have recived the last data, that means we have lost connection

? ? resetData(); // If connection is lost, reset the data. It prevents unwanted behavior, for example if a drone jas a throttle up, if we lose connection it can keep flying away if we dont reset the function

? }

? // Check whether there is data to be received

? if (radio.available()) {

? ? radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure

? ? lastReceiveTime = millis(); // At this moment we have received the data

? }

?

? // Elevator control

? elevatorValue = map(data.j1PotY, 0, 255, 0, 100);

? elevatorServo.write(elevatorValue);

??

? // Ailerons control

? aileron1Value = map(data.j1PotX, 0, 255, 0, 100);

? aileron1Servo.write(aileron1Value);



? // Rudder control

? rudderValue = map(data.j1PotZ, 0, 255, 0, 100);

? rudderServo.write(rudderValue);


?

}

void resetData() {

? // Reset the values when there is no radio connection - Set initial default values

? data.j1PotX = 127;

? data.j1PotY = 127;

? data.j1PotZ = 127;

}


丐版3通道帶屏體感遙控器制作的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
德令哈市| 乐都县| 徐汇区| 安新县| 平远县| 兴安县| 大英县| 宣城市| 兴安县| 迁安市| 唐山市| 二连浩特市| 勐海县| 车险| 周宁县| 延津县| 榆中县| 长武县| 凌源市| 镇巴县| 汝州市| 禄劝| 安图县| 永安市| 莒南县| 定边县| 浮梁县| 平谷区| 克东县| 湘潭县| 新晃| 灵宝市| 高邑县| 河间市| 扎鲁特旗| 新蔡县| 岳池县| 石棉县| 宁明县| 凤台县| 南漳县|