Skip to content

Demonstratia originala

– de completat –

1. Cuvant inainte

Continuare din pagina “Transformarea in Sanguino“.Ok, daca paginile au fost citite in ordinea in care apar in sidebar-ul din dreapta, atunci avem toate ingredientele pentru a restaura aplicatia originala (si chiar a o imbunatati un pic). Trebuie sa stiti ca intotdeauna, in limbajul Arduino (Wiring) veti avea programe mai „obeze” decat daca ati scrie direct in limbajul C sau Assembler. Aplicatia care urmeaza depaseste capacitatile unui ATmega16, asa ca puteti folosi doar de la ATmega32 in sus. In orice caz, noi acum lucram cu ATmega644P. Discutam aici doar de cele 3 microcontrollere suportate de placa EvB 4.3 .

2. Setare placa

… o sa iau o mica pauza pentru ca a trecut peste un an si vreau sa pun placa in functiune din nou, sa refac exemplul … Pentru cei nerabdatori, conexiunile se pot deduce atat din cod, cat si din pagina „Transformarea in Sanguino”, paragraful 7.1

3. Schita

#include <IRremote.h>
#include <Wire.h> // necessary, or the application won't build properly
#include <stdio.h>
#include <PCF8583.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/*****************************************************************************
 *  Restoring the original demo app. which come with EvB4.3 boards
 *
 *  You can set the time by sending it YYMMDDhhmmss; from console.
 *  The semicolon on the end tells it you're done...
 *
 ******************************************************************************/
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

int RECV_PIN = 1;
int STATUS_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;

int correct_address = 0;
PCF8583 p (0xA2);// the device's I2C read address on our board
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);

void setup(void){
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  pinMode(STATUS_PIN, OUTPUT);
  // Start up the library
  sensors.begin();
}

// Storage for the recorded code
int codeType = -1; // The type of code

void showCode(decode_results *results) {
  codeType = results->decode_type;
  //int count = results->rawlen;
  if (codeType == RC5) {
    Serial.print("Received RC5: ");
    // the workaround
    if (results->value >= 0x800) {
      results->value = results->value - 0x800;
    }
    // end workaround
    Serial.println(results->value, HEX);
    lcd.setCursor(14, 0);
    lcd.print("  ");
    lcd.setCursor(14, 0);
    char date[3];
    sprintf(date, "%2X", results->value);
    lcd.print(date);
  }
  else{
    Serial.println("Received different code!");
  }
}

void loop(void){
  //reading time setup from the serial console
  if(Serial.available() > 0){
       Serial.println("receiving...");
       p.year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48)) + 2000;
       p.month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
       p.day = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
       p.hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
       p.minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
       p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
       // Use of (byte) type casting and ascii math to achieve result.

       if(Serial.read() == ';'){
         Serial.println("setting date");
         p.set_time();
       }
  }
  //
  p.get_time();
  char date[9];
  sprintf(date, "%02d/%02d/%02d",
	  p.year, p.month, p.day);
  lcd.setCursor(0, 0);
  lcd.print(date);
  lcd.print(" IR:");
  // print IR RC5 code
  //digitalWrite(STATUS_PIN, HIGH); //switch off the LED on our board (common anode)
  if (irrecv.decode(&results)) {
    digitalWrite(STATUS_PIN, LOW);
    showCode(&results);
    irrecv.resume(); // resume receiver
    delay(50);
    digitalWrite(STATUS_PIN, HIGH); //switch off the LED on our board (common anode)
  }
  //
  char time[9];
  sprintf(time, "%02d:%02d:%02d",
	  p.hour, p.minute, p.second);
  //Serial.println(time);
  lcd.setCursor(0, 1);
  lcd.print(time);
  lcd.print(" T:");
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  sensors.requestTemperatures(); // Send the command to get temperatures
  lcd.print(sensors.getTempCByIndex(0));
}

4. Rezultate

Pe primul rand in stanga avem data calendaristica iar in dreapta este afisat codul receptionat in infrarosu. Pe al doilea rand avem in stanga ceasul, iar in deapta avem temperatura in grade celsius. LED-ul verde semnalizeaza cand este receptionat cod in infrarosu de la telecomanda cu protocol RC5. Si cu asta, am atins cu succes primul obiectiv.

Lasă un comentariu

Va rog, nu folositi limbaj de messenger. Multumesc!

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

%d blogeri au apreciat asta: