DanieleCalisti

Arduino

Oct 16th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <IRremote.h>
  2. #include <Wire.h>
  3. #include <SoftwareSerial.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Adafruit_SSD1306.h>
  6.  
  7. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  8. #define SCREEN_HEIGHT 32 // OLED display height, in pixels
  9.  
  10. // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  11. #define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
  12. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  13.  
  14. SoftwareSerial SSerial(6,7); //RX, TX
  15.  
  16. IRsend irsend;
  17. 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};
  18. 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};
  19. 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};
  20. 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};
  21.  
  22.  
  23. int freq_ir = 38; //Khz
  24.  
  25. String comando="";
  26.  
  27. void setup() {
  28.   pinMode(4,INPUT);
  29.   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
  30.     Serial.println(F("SSD1306 allocation failed"));
  31.     for(;;); // Don't proceed, loop forever
  32.   }
  33.   // Show initial display buffer contents on the screen --
  34.   // the library initializes this with an Adafruit splash screen.
  35.   display.display();
  36.   // Clear the buffer
  37.   display.clearDisplay();  
  38.  
  39.   stampaSuSchermoOled("Aspetto i\ncomandi...");
  40.  
  41.  
  42.   SSerial.begin(9600);
  43.   Serial.begin(9600);    
  44.   Serial.println("pronto");
  45. }
  46.  
  47. void loop() {
  48.  
  49.   /*if(digitalRead(4.))
  50.   {
  51.     if(acceso)
  52.     {
  53.       irsend.sendRaw(rawData, 68, freq_ir);
  54.       stampaSuSchermoOled("Spengo TV!");
  55.       acceso = false;
  56.       delay(1000);
  57.       }else
  58.       {
  59.         irsend.sendRaw(rawData, 68, freq_ir);
  60.         stampaSuSchermoOled("Accendo\nLa tua TV!");
  61.         acceso = true;
  62.         delay(1000);
  63.       }
  64.   }*/
  65.  
  66.   if(SSerial.available())
  67.   {
  68.     char carattere = SSerial.read();
  69.         comando += carattere;
  70.         Serial.println(comando);
  71.     if(comando != "")
  72.     {
  73.       if(comando == "accendi" || comando == "Accendi")
  74.       {
  75.         irsend.sendRaw(accendiTv,67, freq_ir);
  76.         stampaSuSchermoOled("Accendo\nla tua TV!");
  77.         comando = "";
  78.       }
  79.       if(comando == "spegni" || comando == "Spegni")
  80.       {
  81.         irsend.sendRaw(accendiTv,67, freq_ir);
  82.         stampaSuSchermoOled("Spengo\nla tua TV!");
  83.         comando = "";
  84.       }
  85.       if(comando == "netflix" || comando == "Netflix" )
  86.       {
  87.         mettiNetflix();
  88.         stampaSuSchermoOled("Metto\n Netflix!");
  89.         comando = "";
  90.       }
  91.     }
  92.   }
  93.  
  94.    
  95. }
  96.  
  97. void stampaSuSchermoOled(String stringa)
  98. {
  99.   display.clearDisplay();  
  100.   display.setTextSize(2);      // Normal 1:1 pixel scale
  101.   display.setTextColor(WHITE); // Draw white text
  102.   display.setCursor(0, 0);     // Start at top-left corner
  103.   display.cp437(true);         // Use full 256 char 'Code Page 437' font
  104.   display.print(stringa);
  105.   display.display();
  106. }
  107.  
  108. void mettiNetflix()
  109. {
  110.   irsend.sendRaw(tastoCentrale,67,freq_ir);
  111.   delay(500);
  112.   for(int i=0;i<3;i++)
  113.   {
  114.     irsend.sendRaw(tastoDestro,67,freq_ir);
  115.     delay(500);
  116.   }
  117.   irsend.sendRaw(tastoOk,67,freq_ir);
  118.   delay(500);
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment