驴友花雕
				发表于 2019-6-13 08:58:12	
			
		
				
					驴友花雕
				发表于 2019-6-13 09:04:19	
			
		
				
					驴友花雕
				发表于 2019-6-13 09:11:25	
			
		
				
					驴友花雕
				发表于 2019-6-13 09:19:48	
			
		
				
					驴友花雕
				发表于 2019-6-13 10:04:30	
			
		实验方案三,有点像了,就是程序复杂些了,暂时这样吧(以后再尝试简化)
				
					驴友花雕
				发表于 2019-6-13 10:08:23	
			
		
				
					驴友花雕
				发表于 2019-6-13 10:12:46	
			
		
				
					驴友花雕
				发表于 2019-6-13 10:22:58	
			
		11 LED_RGB:全彩 LED 彩虹变化
/*
Eagler8实验程序列表
11 LED_RGB:全彩 LED 彩虹变化
 */
#define LEDR 9
#define LEDG 10
#define LEDB 11
int i = 0;
void setup()
{
pinMode(LEDG,OUTPUT);
pinMode(LEDB,OUTPUT);
pinMode(LEDR,OUTPUT);
}
void loop()
{
analogWrite(LEDR,255);
delay(1000);    //hong
analogWrite(LEDG,120);
delay(1000);   //cheng
analogWrite(LEDR,255);
analogWrite(LEDG,220);
delay(1000);   //huang
analogWrite(LEDR,0);
analogWrite(LEDG,255);
delay(1000);   //lv
analogWrite(LEDB,255);
delay(1000);   //qing
analogWrite(LEDG,0);
analogWrite(LEDB,255);
delay(1000);   //lan
analogWrite(LEDR,255);
analogWrite(LEDG,0);
delay(1000);   //zi 
analogWrite(LEDG,255);
delay(1000);   //bai   
analogWrite(LEDG,0);
analogWrite(LEDB,0);
analogWrite(LEDR,255);
delay(1000);   //zi    
for(i=0;i<255;i++)
{
    analogWrite(LEDG,i);
    delay(10);
}
for(i=255;i>0;i--)
{
    analogWrite(LEDR,i);
    delay(10);
}
   for(i=0;i<255;i++)
{
    analogWrite(LEDB,i);
    delay(10);
}
for(i=255;i>0;i--)
{
    analogWrite(LEDG,i);
    delay(10);
}
   for(i=0;i<255;i++)
{
    analogWrite(LEDR,i);
    delay(10);
}
   for(i=0;i<255;i++)
{
    analogWrite(LEDG,i);
    delay(10);
}
analogWrite(LEDG,0);
analogWrite(LEDB,0);
analogWrite(LEDR,0);
}
				
					驴友花雕
				发表于 2019-6-13 10:52:43	
			
		
				
					驴友花雕
				发表于 2019-6-13 10:57:13	
			
		图形编程,估计与实验十相类似,差别不大				
					驴友花雕
				发表于 2019-6-13 11:53:45	
			
		 本帖最后由 驴友花雕 于 2023-8-23 16:48 编辑 
12 红外控制,接收红外命令控制板载LED灯亮灭
/*
Eagler8实验程序列表
12 红外控制,接收红外命令控制板载LED灯亮灭(1号键灭,2号键亮,控制距离1-8米,兼容市面上大部分红外遥控器)
说明:开关按键可以自己定义
*/
#include <IRremote.h>
int RECV_PIN = 8;
int LED_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == 0xFFA25D)
    {
      digitalWrite(LED_PIN, LOW);
    } else if (results.value == 0xFF629D)
    {
      digitalWrite(LED_PIN, HIGH);
    }
    irrecv.resume();
}
delay(100);
}
				
					驴友花雕
				发表于 2019-6-13 12:00:30	
			
		
				
					驴友花雕
				发表于 2019-6-13 12:47:43	
			
		任何键均可控制
				
					驴友花雕
				发表于 2019-6-13 12:50:54	
			
		
				
					驴友花雕
				发表于 2019-6-13 14:48:16	
			
		13 IRrecord:串口显示读取的红外遥控代码
/*
Eagler8实验程序列表
13 IRrecord:串口显示读取的红外遥控代码
 */
#include <IRremote.h>
int RECV_PIN = 8;
int BUTTON_PIN = 12;
int STATUS_PIN = 13;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(BUTTON_PIN, INPUT);
pinMode(STATUS_PIN, OUTPUT);
}
// Storage for the recorded code
int codeType = -1; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes; // The durations if raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state
// Stores the code for later playback
// Most of this code is just logging
void storeCode(decode_results *results) {
codeType = results->decode_type;
int count = results->rawlen;
if (codeType == UNKNOWN) {
    Serial.println("Received unknown code, saving as raw");
    codeLen = results->rawlen - 1;
    // To store raw codes:
    // Drop first value (gap)
    // Convert from ticks to microseconds
    // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    for (int i = 1; i <= codeLen; i++) {
      if (i % 2) {
      // Mark
      rawCodes = results->rawbuf*USECPERTICK - MARK_EXCESS;
      Serial.print(" m");
      } 
      else {
      // Space
      rawCodes = results->rawbuf*USECPERTICK + MARK_EXCESS;
      Serial.print(" s");
      }
      Serial.print(rawCodes, DEC);
    }
    Serial.println("");
}
else {
    if (codeType == NEC) {
      Serial.print("Received NEC: ");
      if (results->value == REPEAT) {
      // Don't record a NEC repeat value as that's useless.
      Serial.println("repeat; ignoring.");
      return;
      }
    } 
    else if (codeType == SONY) {
      Serial.print("Received SONY: ");
    } 
    else if (codeType == RC5) {
      Serial.print("Received RC5: ");
    } 
    else if (codeType == RC6) {
      Serial.print("Received RC6: ");
    } 
    else {
      Serial.print("Unexpected codeType ");
      Serial.print(codeType, DEC);
      Serial.println("");
    }
    Serial.println(results->value, HEX);
    codeValue = results->value;
    codeLen = results->bits;
}
}
void sendCode(int repeat) {
if (codeType == NEC) {
    if (repeat) {
      irsend.sendNEC(REPEAT, codeLen);
      Serial.println("Sent NEC repeat");
    } 
    else {
      irsend.sendNEC(codeValue, codeLen);
      Serial.print("Sent NEC ");
      Serial.println(codeValue, HEX);
    }
} 
else if (codeType == SONY) {
    irsend.sendSony(codeValue, codeLen);
    Serial.print("Sent Sony ");
    Serial.println(codeValue, HEX);
} 
else if (codeType == RC5 || codeType == RC6) {
    if (!repeat) {
      // Flip the toggle bit for a new button press
      toggle = 1 - toggle;
    }
    // Put the toggle bit into the code to send
    codeValue = codeValue & ~(1 << (codeLen - 1));
    codeValue = codeValue | (toggle << (codeLen - 1));
    if (codeType == RC5) {
      Serial.print("Sent RC5 ");
      Serial.println(codeValue, HEX);
      irsend.sendRC5(codeValue, codeLen);
    } 
    else {
      irsend.sendRC6(codeValue, codeLen);
      Serial.print("Sent RC6 ");
      Serial.println(codeValue, HEX);
    }
} 
else if (codeType == UNKNOWN /* i.e. raw */) {
    // Assume 38 KHz
    irsend.sendRaw(rawCodes, codeLen, 38);
    Serial.println("Sent raw");
}
}
int lastButtonState;
void loop() {
// If button pressed, send the code.
int buttonState = digitalRead(BUTTON_PIN);
if (lastButtonState == HIGH && buttonState == LOW) {
    Serial.println("Released");
    irrecv.enableIRIn(); // Re-enable receiver
}
if (buttonState) {
    Serial.println("Pressed, sending");
    digitalWrite(STATUS_PIN, HIGH);
    sendCode(lastButtonState == buttonState);
    digitalWrite(STATUS_PIN, LOW);
    delay(50); // Wait a bit between retransmissions
} 
else if (irrecv.decode(&results)) {
    digitalWrite(STATUS_PIN, HIGH);
    storeCode(&results);
    irrecv.resume(); // resume receiver
    digitalWrite(STATUS_PIN, LOW);
}
lastButtonState = buttonState;
}
				
					驴友花雕
				发表于 2019-6-13 14:54:53	
			
		
				
					驴友花雕
				发表于 2019-6-13 16:14:22	
			
		
				
					驴友花雕
				发表于 2019-6-13 16:25:31	
			
		
				
					驴友花雕
				发表于 2019-6-13 17:09:25	
			
		Mind+只用简单的三行程序,就能读出红外遥控器各个按键的编码
				
					驴友花雕
				发表于 2019-6-13 17:13:52	
			
		
				
					驴友花雕
				发表于 2019-6-13 17:27:39	
			
		
			
		页: 
1 
2 
[3] 
4 
5 
6 
7 
8 
9 
10