Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- #include <Wire.h>
- #include <SoftwareSerial.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 32 // OLED display height, in pixels
- // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
- #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- SoftwareSerial SSerial(6,7); //RX, TX
- IRsend irsend;
- unsigned int accendiTv[67] = {4500,4450, 600,1650, 600,1650, 550,1650, 600,550, 550,550, 550,550, 600,550, 550,550, 550,1650, 600,1650, 600,1650, 550,550, 600,550, 550,550, 550,550, 600,500, 600,550, 550,1650, 600,550, 550,550, 600,500, 600,550, 550,550, 600,500, 600,1650, 600,500, 600,1650, 600,1650, 550,1650, 600,1650, 600,1650, 550,1650, 600};
- unsigned int tastoDestro[67] = {4550,4450, 600,1650, 550,1700, 550,1650, 600,550, 550,550, 550,550, 600,550, 550,600, 500,1700, 550,1700, 550,1650, 550,600, 550,550, 550,600, 500,600, 550,550, 550,550, 550,1700, 550,550, 550,600, 550,550, 550,1700, 550,1700, 500,600, 550,1650, 550,600, 550,1650, 550,1700, 550,1700, 550,550, 550,550, 550,1700, 550};
- unsigned int tastoCentrale[67] = {4550,4450, 550,1650, 600,1650, 600,1650, 550,550, 600,550, 550,550, 550,550, 600,500, 600,1650, 600,1650, 550,1650, 600,550, 550,600, 550,500, 600,550, 550,550, 600,1650, 550,550, 600,500, 600,1650, 550,1700, 550,1650, 600,1650, 550,550, 550,600, 550,1650, 600,1650, 600,500, 600,550, 550,550, 600,550, 550,1650, 600};
- unsigned int tastoOk[67] = {4500,4450, 550,1700, 550,1700, 550,1650, 550,600, 550,550, 550,550, 550,550, 600,500, 600,1700, 550,1700, 500,1700, 550,550, 550,600, 550,550, 550,600, 500,600, 550,550, 550,550, 550,600, 550,1650, 550,550, 600,1650, 550,1700, 550,550, 550,1700, 550,1650, 600,1650, 550,600, 500,1700, 550,600, 500,550, 600,1700, 500};
- int freq_ir = 38; //Khz
- String comando="";
- void setup() {
- pinMode(4,INPUT);
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
- Serial.println(F("SSD1306 allocation failed"));
- for(;;); // Don't proceed, loop forever
- }
- // Show initial display buffer contents on the screen --
- // the library initializes this with an Adafruit splash screen.
- display.display();
- // Clear the buffer
- display.clearDisplay();
- stampaSuSchermoOled("Aspetto i\ncomandi...");
- SSerial.begin(9600);
- Serial.begin(9600);
- Serial.println("pronto");
- }
- void loop() {
- /*if(digitalRead(4.))
- {
- if(acceso)
- {
- irsend.sendRaw(rawData, 68, freq_ir);
- stampaSuSchermoOled("Spengo TV!");
- acceso = false;
- delay(1000);
- }else
- {
- irsend.sendRaw(rawData, 68, freq_ir);
- stampaSuSchermoOled("Accendo\nLa tua TV!");
- acceso = true;
- delay(1000);
- }
- }*/
- if(SSerial.available())
- {
- char carattere = SSerial.read();
- comando += carattere;
- Serial.println(comando);
- if(comando != "")
- {
- if(comando == "accendi" || comando == "Accendi")
- {
- irsend.sendRaw(accendiTv,67, freq_ir);
- stampaSuSchermoOled("Accendo\nla tua TV!");
- comando = "";
- }
- if(comando == "spegni" || comando == "Spegni")
- {
- irsend.sendRaw(accendiTv,67, freq_ir);
- stampaSuSchermoOled("Spengo\nla tua TV!");
- comando = "";
- }
- if(comando == "netflix" || comando == "Netflix" )
- {
- mettiNetflix();
- stampaSuSchermoOled("Metto\n Netflix!");
- comando = "";
- }
- }
- }
- }
- void stampaSuSchermoOled(String stringa)
- {
- display.clearDisplay();
- display.setTextSize(2); // Normal 1:1 pixel scale
- display.setTextColor(WHITE); // Draw white text
- display.setCursor(0, 0); // Start at top-left corner
- display.cp437(true); // Use full 256 char 'Code Page 437' font
- display.print(stringa);
- display.display();
- }
- void mettiNetflix()
- {
- irsend.sendRaw(tastoCentrale,67,freq_ir);
- delay(500);
- for(int i=0;i<3;i++)
- {
- irsend.sendRaw(tastoDestro,67,freq_ir);
- delay(500);
- }
- irsend.sendRaw(tastoOk,67,freq_ir);
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment