added arduino, modified build

This commit is contained in:
2020-02-02 15:28:36 -08:00
parent 0189d519c6
commit 6480bc593f
3583 changed files with 1305025 additions and 247 deletions

View File

@@ -0,0 +1,163 @@
/* Infrared_NeoPixel.ino Example sketch for IRLib2 and Circuit Playground Express
Illustrates how to change NeoPixel patterns and colors using
an IR remote. Programmed to use IR codes for Adafruit mini remote
https://www.adafruit.com/product/389
Press the following keys on the remote:
vol- decrease brightness
vol+ increase brightness
right arrow rotate clockwise
left arrow rotate counterclockwise
up arrow rotate faster
down arrow rotate slower
0 rainbow pattern
1 candy cane pattern
2 one red pixel
3 decreased solid colors
4 increase solid colors
*/
#include <Adafruit_CircuitPlayground.h>
#include "adafruit_mini_codes.h"
#if !defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
#error "Infrared support is only for the Circuit Playground Express, it doesn't work with the Classic version"
#endif
//Pattern numbers
#define RAINBOW 0
#define CANDY_CANE 1
#define JUST_ONE 2
#define MONOCHROME 3
uint8_t i,j,Phase, Pattern;
int8_t Direction, Mono;
int16_t Bright, Speed;
void Show_Pattern(void) {
CircuitPlayground.setBrightness(Bright);
for(i=0;i<11;i++) {
j= (20+i+Phase*Direction) % 10;
switch (Pattern) {
case RAINBOW:
CircuitPlayground.setPixelColor(j, CircuitPlayground.colorWheel(25*i));
break;
case CANDY_CANE:
if((i % 5)<2) {
CircuitPlayground.setPixelColor(j, 255,0,0);
} else {
CircuitPlayground.setPixelColor(j, 255,255,255);
}
break;
case JUST_ONE:
if(i<2) {
CircuitPlayground.setPixelColor(j, 255,0,0);
} else {
CircuitPlayground.setPixelColor(j, 0,0,0);
}
break;
case MONOCHROME:
CircuitPlayground.setPixelColor(i, CircuitPlayground.colorWheel(25*Mono));
break;
}
}
}
void setup() {
CircuitPlayground.begin();
Serial.begin(9600);
CircuitPlayground.irReceiver.enableIRIn(); // Start the receiver
Bright=8; Phase=0; Pattern=2; Direction=1; Speed=300;
Mono=0;
}
void loop() {
// First up, display whatever neopixel patterm we're doing
Show_Pattern();
// a small pause
delay(Speed);
// go to next phase next time
Phase++;
if (Phase >= 10) {
Phase = 0;
}
// Did we get any infrared signals?
if (! CircuitPlayground.irReceiver.getResults()) {
return;
}
// Did we get any decodable messages?
if (! CircuitPlayground.irDecoder.decode()) {
CircuitPlayground.irReceiver.enableIRIn(); // Restart receiver
return;
}
// We can print out the message if we want...
CircuitPlayground.irDecoder.dumpResults(false);
// Did we get any NEC remote messages?
if (! CircuitPlayground.irDecoder.protocolNum == NEC) {
CircuitPlayground.irReceiver.enableIRIn(); // Restart receiver
return;
}
// What message did we get?
switch(CircuitPlayground.irDecoder.value) {
case ADAF_MINI_0_10_PLUS:
Serial.println("Rainbow mode!");
Pattern = RAINBOW;
break;
case ADAF_MINI_1:
Serial.println("Candy Cane mode!");
Pattern = CANDY_CANE;
break;
case ADAF_MINI_2:
Serial.println("Just One mode!");
Pattern = JUST_ONE;
break;
case ADAF_MINI_3:
Serial.println("Monochrome mode, less");
Pattern = MONOCHROME;
Mono--;
if (Mono < 0) {
Mono = 9;
}
break;
case ADAF_MINI_4:
Serial.println("Monochrome mode, more");
Pattern = MONOCHROME;
Mono++;
if (Mono > 9) {
Mono = 0;
}
break;
case ADAF_MINI_LEFT_ARROW:
Serial.println("Counter-Clockwise");
Direction = 1;
break;
case ADAF_MINI_RIGHT_ARROW:
Serial.println("Clockwise");
Direction = -1;
break;
case ADAF_MINI_VOLUME_UP:
Serial.println("Brighter");
Bright = min(255, Bright+2);
break;
case ADAF_MINI_VOLUME_DOWN:
Serial.println("Dimmer");
Bright = max(0, Bright-2);
break;
case ADAF_MINI_UP_ARROW:
Serial.println("Faster");
Speed = max(50, Speed-50);
break;
case ADAF_MINI_DOWN_ARROW:
Serial.println("Slower");
Speed = min(2000, Speed+50);
break;
}
//Restart receiver
CircuitPlayground.irReceiver.enableIRIn();
}

View File

@@ -0,0 +1,28 @@
/*
IR codes for Adafruit mini remote
https://www.adafruit.com/product/389
Uses NEC protocol
*/
#define ADAF_MINI_VOLUME_DOWN 0xfd00ff
#define ADAF_MINI_PLAY_PAUSE 0xfd807f
#define ADAF_MINI_VOLUME_UP 0xfd40bf
#define ADAF_MINI_SETUP 0xfd20df
#define ADAF_MINI_UP_ARROW 0xfda05f
#define ADAF_MINI_STOP_MODE 0xfd609f
#define ADAF_MINI_LEFT_ARROW 0xfd10ef
#define ADAF_MINI_ENTER_SAVE 0xfd906f
#define ADAF_MINI_RIGHT_ARROW 0xfd50af
#define ADAF_MINI_0_10_PLUS 0xfd30cf
#define ADAF_MINI_DOWN_ARROW 0xfdb04f
#define ADAF_MINI_REPEAT 0xfd708f
#define ADAF_MINI_1 0xfd08f7
#define ADAF_MINI_2 0xfd8877
#define ADAF_MINI_3 0xfd48b7
#define ADAF_MINI_4 0xfd28d7
#define ADAF_MINI_5 0xfda857
#define ADAF_MINI_6 0xfd6897
#define ADAF_MINI_7 0xfd18e7
#define ADAF_MINI_8 0xfd9867
#define ADAF_MINI_9 0xfd58a7

View File

@@ -0,0 +1,29 @@
/* Infrared_Read.ino Example sketch for IRLib2 and Circuit Playground Express
Illustrates how to receive an IR signal, decode it and print
information about it to the serial monitor.
*/
#include <Adafruit_CircuitPlayground.h>
#if !defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
#error "Infrared support is only for the Circuit Playground Express, it doesn't work with the Classic version"
#endif
void setup() {
CircuitPlayground.begin();
Serial.begin(9600);
while (!Serial); // Wait until serial console is opened
CircuitPlayground.irReceiver.enableIRIn(); // Start the receiver
Serial.println("Ready to receive IR signals");
}
void loop() {
//Continue looping until you get a complete signal received
if (CircuitPlayground.irReceiver.getResults()) {
CircuitPlayground.irDecoder.decode(); //Decode it
CircuitPlayground.irDecoder.dumpResults(false); //Now print results. Use false for less detail
CircuitPlayground.irReceiver.enableIRIn(); //Restart receiver
}
}

View File

@@ -0,0 +1,66 @@
/* Infrared_Record.ino Example sketch for IRLib2 and Circuit Playground Express
Illustrates how to receive an IR signal, decode and save it.
Then retransmit it whenever you push the left pushbutton.
*/
#include <Adafruit_CircuitPlayground.h>
#if !defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
#error "Infrared support is only for the Circuit Playground Express, it doesn't work with the Classic version"
#endif
/* IR signals consist of a protocol number, a value, and a number of bits.
* Store all of these values for future use.
*/
uint8_t IR_protocol;
uint32_t IR_value;
uint16_t IR_bits;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Send an IR signal and I will record it.");
Serial.println("Press the left button and we will retransmit it.");
CircuitPlayground.begin();
CircuitPlayground.irReceiver.enableIRIn(); // Start the receiver
IR_protocol=0; // Indicates we've not received a code yet
}
void loop() {
/* Receiver will look for a signal and when wa complete frame of data
* has been received, getResults() returns true. Once that happens,
* the receiver stops reccording so you will need to restart it
* after you have processed the data.
*/
if(CircuitPlayground.irReceiver.getResults()) {
//attempt to decode it
if(CircuitPlayground.irDecoder.decode()) {
Serial.println("IR decoded");
//Print the results. Change parameter to "true" for verbose output.
CircuitPlayground.irDecoder.dumpResults(false);
Serial.println("Saving results. Press left button to retransmit.");
IR_protocol=CircuitPlayground.irDecoder.protocolNum;
IR_value= CircuitPlayground.irDecoder.value;
IR_bits= CircuitPlayground.irDecoder.bits;
}
CircuitPlayground.irReceiver.enableIRIn(); //Restart receiver
}
/* If the left button is pressed and we have received a code
* retransmit it using the sender.
*/
if (CircuitPlayground.leftButton()) {
Serial.println("Left button pressed!");
if(IR_protocol) {
CircuitPlayground.irSend.send(IR_protocol, IR_value, IR_bits);
Serial.println("Sending recorded IR signal");
Serial.print("Protocol:"); Serial.print(IR_protocol,DEC);
Serial.print(" Value:0x"); Serial.print(IR_value,HEX);
Serial.print(" Bits:"); Serial.println(IR_bits,DEC);
} else {
Serial.println("No signal saved yet.");
}
}
}

View File

@@ -0,0 +1,33 @@
/* Infrared_Send.ino Example sketch for IRLib2 and Circuit Playground Express
Illustrates how to transmit an IR signal whenever you do push one of the
built-in pushbuttons.
*/
#include <Adafruit_CircuitPlayground.h>
#if !defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
#error "Infrared support is only for the Circuit Playground Express, it doesn't work with the Classic version"
#endif
void setup() {
CircuitPlayground.begin();
}
//Defines for a Samsung TV using NECx protocol
#define MY_PROTOCOL NECX
#define MY_BITS 32
#define MY_MUTE 0xE0E0F00F
#define MY_POWER 0xE0E040BF
void loop() {
// If the left button is pressed send a mute code.
if (CircuitPlayground.leftButton()) {
CircuitPlayground.irSend.send(MY_PROTOCOL,MY_MUTE,MY_BITS);
while (CircuitPlayground.leftButton()) {}//wait until button released
}
// If the right button is pressed send a power code.
if (CircuitPlayground.rightButton()) {
CircuitPlayground.irSend.send(MY_PROTOCOL,MY_POWER,MY_BITS);
while (CircuitPlayground.rightButton()) {}//wait until button released
}
}

View File

@@ -0,0 +1,107 @@
/* Infrared_Testpattern.ino Example sketch for IRLib2 and Circuit Playground Express
* Send an easily recognized pattern of bits from one Arduino
* to another to verify that your protocol is working. Load
* this sketch to send a signal. Use the "dump" sketch on the other
* Arduino to receive codes. Open the serial monitor and type the
* number Of the protocol want to test.
*/
#include <Adafruit_CircuitPlayground.h>
#if !defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
#error "Infrared support is only for the Circuit Playground Express, it doesn't work with the Classic version"
#endif
void setup() {
CircuitPlayground.begin();
Serial.begin(9600);
while (!Serial); // Wait for serial console
Serial.println("Type the protocol number: 1-12 Or '-1' for all");
}
void sendOne(uint8_t protocol, uint32_t data, uint16_t data2 = 0, uint8_t khz = 0) {
Serial.print("Protocol #"); Serial.print(protocol, DEC);
Serial.print("\t"); Serial.print(Pnames(protocol));
Serial.print("\t data = 0x"); Serial.print(data, HEX);
if (data2) {
Serial.print("\t data2 = 0x"); Serial.print(data2, HEX);
Serial.print(" "); Serial.print(data2, DEC);
Serial.print(" dec");
}
if (khz) {
CircuitPlayground.irSend.send(protocol, data, data2, khz);
Serial.print(" khz="); Serial.println(khz,DEC);
} else {
CircuitPlayground.irSend.send(protocol, data, data2);
Serial.println();
}
delay(2000);
}
#define PATTERN1 0x12345678
#define ALL1S 0xFFFFFFFF
void doTest (uint8_t P) {
switch (P) {
case 1: sendOne(1,PATTERN1); //NEC Regular data
sendOne(1,REPEAT_CODE); //NEC Special ditto repeat code
sendOne(1,PATTERN1,40); //Pioneer is NEC with 40 kHz modulation
break;
case 2: sendOne(2,PATTERN1,12); //Sony 12 bits
sendOne(2,PATTERN1,15); //Sony 15 bits
sendOne(2,PATTERN1,20); //Sony 20 bits
break; //Note: Sony always sends three copies of signal
case 3: sendOne(3,ALL1S,13); //RC5
sendOne(3,ALL1S,14); //RC5-F7
sendOne(3,ALL1S,14,57); //RC5-F7-57
break;
case 4: sendOne(4,0x0ffff,20); //RC6-0-16 Original Phillips RC6
sendOne(4,0xcfffff,24); //RC6-6-20 Used by some Sky and Sky+ remotes
sendOne(4,0xcfffff,28); //RC6-6-24 a.k.a. "Replay" protocol
sendOne(4,ALL1S,32); //RC6-6-32 a.k.a. "MCE" protocol
break;
case 5: sendOne(5,ALL1S); //Panasonic_Old 22 bits used by some SA and Cisco cable boxes
break;
case 6: //JVC use "true" for first frame, "false" for repeats
//When "true" it automatically sends one repeat. Use "false"
//for additional repeats. The 2 lines below will actually send
//a total of 3 frames... A first and 2 repeats.
sendOne(6,PATTERN1,true);
sendOne(6,PATTERN1,false);
break;
case 7: sendOne(7,PATTERN1); //NECx used by many Samsung TVs
sendOne(7,REPEAT_CODE); //Some varieties use ditto
break;
case 8: sendOne(8,0x12345,0x1234);//Samsung36 16 bit address +20 data
break;
case 9: sendOne(9,PATTERN1); //G.I.Cable 16 bits with ditto repeat
sendOne(9,REPEAT_CODE); //This will report NEC if both protocols used
break;
case 10: sendOne(10,PATTERN1); //DirecTV default no repeat, 38 khz
sendOne(10,PATTERN1,true);//3rd parameter is repeat flag
sendOne(10,PATTERN1,false,40);//4th is khz, 38, 40, 57 are legal
break;
case 11: sendOne(11,ALL1S,12); //RCMM Phillips protocol used by U-Verse
sendOne(11,ALL1S,24); //also 24 or 32 bit possible
sendOne(11,ALL1S,32);
break;
case 12: sendOne(12,CYKM_MOUSE_MOVE+CYKM_DIR_RIGHT);//Move mouse right
sendOne(12,CYKM_MOUSE_MOVE+CYKM_DIR_UP); //Move mouse up
sendOne(12,CYKM_MOUSE_MOVE+CYKM_DIR_LEFT); //Move mouse left
sendOne(12,CYKM_MOUSE_MOVE+CYKM_DIR_DOWN); //Move mouse down
break;
};
}
void loop() {
if (Serial.available () > 0) {
int16_t i = Serial.parseInt();
if(i==-1) {
for(i=1;i<=12;i++) {
doTest(i);
};
} else {
doTest(i);
}
}
}