Guest User

Untitled

a guest
Mar 10th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. #include <VirtualWire.h>
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4.  
  5. #define ledPin 10
  6. #define buttonPin 9
  7.  
  8. #define ONE_WIRE_BUS 2  // Data wire is plugged into pin 2 on the Arduino
  9. OneWire oneWire(ONE_WIRE_BUS);  // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  10. DallasTemperature sensors(&oneWire);  // Pass our oneWire reference to Dallas Temperature
  11.  
  12. char wiadomosc[100];
  13.  
  14. void setup() {
  15.   vw_set_ptt_inverted(true);
  16.   vw_setup(2000);
  17.  
  18.   pinMode(ledPin, OUTPUT);
  19.   pinMode(buttonPin, INPUT);
  20.  
  21.   sensors.begin();
  22.  
  23.   //Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27.   sensors.requestTemperatures();
  28.   float temp0 = sensors.getTempCByIndex(0);
  29.   float temp1 = sensors.getTempCByIndex(1);
  30.   float temp2 = sensors.getTempCByIndex(2);
  31.   //snprintf(wiadomosc, sizeof(wiadomosc), "%f", temp);
  32.  
  33.   char space = ' ';
  34.   strcpy(wiadomosc,floatToString(temp0));
  35.   strcpy(wiadomosc+5,&space);
  36.   strcpy(wiadomosc+6,floatToString(temp1));
  37.   strcpy(wiadomosc+10,&space);
  38.   strcpy(wiadomosc+11,floatToString(temp2));
  39.  
  40.   vw_send((uint8_t *)wiadomosc, strlen(wiadomosc));
  41.   vw_wait_tx();
  42.  
  43.   //Serial.print("Send ");
  44.   //Serial.print(temp);
  45.   //Serial.println(wiadomosc);
  46.  
  47.    digitalWrite(ledPin, HIGH);
  48.    delay(50);
  49.    digitalWrite(ledPin, LOW);
  50.    if(digitalRead(buttonPin) == LOW){
  51.       strcpy(wiadomosc, "---------");
  52.      
  53.       vw_send((uint8_t *)wiadomosc, strlen(wiadomosc));
  54.       vw_wait_tx();
  55.      
  56.       digitalWrite(ledPin, HIGH);
  57.       delay(50);
  58.       digitalWrite(ledPin, LOW);
  59.       delay(50);
  60.       digitalWrite(ledPin, HIGH);
  61.       delay(50);
  62.       digitalWrite(ledPin, LOW);
  63.    }
  64.    delay(600);
  65.  
  66. }
  67.  
  68.  
  69. char* floatToString(float x){
  70.   char string[21], buff[10], dot[2]=".";
  71.   itoa((int) (x), string, 10);
  72.   int xMod = (int)(x * 100) % 100;
  73.   itoa(xMod, buff, 10);
  74.   strcat(string, dot);
  75.   strcat(string, buff);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment