Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <VirtualWire.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ledPin 10
- #define buttonPin 9
- #define ONE_WIRE_BUS 2 // Data wire is plugged into pin 2 on the Arduino
- OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature
- char wiadomosc[100];
- void setup() {
- vw_set_ptt_inverted(true);
- vw_setup(2000);
- pinMode(ledPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- sensors.begin();
- //Serial.begin(9600);
- }
- void loop() {
- sensors.requestTemperatures();
- float temp0 = sensors.getTempCByIndex(0);
- float temp1 = sensors.getTempCByIndex(1);
- float temp2 = sensors.getTempCByIndex(2);
- //snprintf(wiadomosc, sizeof(wiadomosc), "%f", temp);
- char space = ' ';
- strcpy(wiadomosc,floatToString(temp0));
- strcpy(wiadomosc+5,&space);
- strcpy(wiadomosc+6,floatToString(temp1));
- strcpy(wiadomosc+10,&space);
- strcpy(wiadomosc+11,floatToString(temp2));
- vw_send((uint8_t *)wiadomosc, strlen(wiadomosc));
- vw_wait_tx();
- //Serial.print("Send ");
- //Serial.print(temp);
- //Serial.println(wiadomosc);
- digitalWrite(ledPin, HIGH);
- delay(50);
- digitalWrite(ledPin, LOW);
- if(digitalRead(buttonPin) == LOW){
- strcpy(wiadomosc, "---------");
- vw_send((uint8_t *)wiadomosc, strlen(wiadomosc));
- vw_wait_tx();
- digitalWrite(ledPin, HIGH);
- delay(50);
- digitalWrite(ledPin, LOW);
- delay(50);
- digitalWrite(ledPin, HIGH);
- delay(50);
- digitalWrite(ledPin, LOW);
- }
- delay(600);
- }
- char* floatToString(float x){
- char string[21], buff[10], dot[2]=".";
- itoa((int) (x), string, 10);
- int xMod = (int)(x * 100) % 100;
- itoa(xMod, buff, 10);
- strcat(string, dot);
- strcat(string, buff);
- }
Advertisement
Add Comment
Please, Sign In to add comment