Hi , I'm trying to combine the temperature appication and the slide application (with the LEDs) to one application. when I am trying to connect the application it freezes, appart the two applications work but to merge it I still have some problems. the Arduino program that I currently have.
#include <OneWire.h>
int DS18S20_Pin = 2;
//temperatuur chip in/ out
OneWire ds(DS18S20_Pin);
const int greenPin = 9;
const int bluePin =11;
const int redPin2 = 10;
byte serialA;
void setup() {
Serial.begin(9600);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin2, OUTPUT);
}
void loop() { // word steets herhaalt
if (serialA == 49){float temperature = getTemp();
serialA = 0;
}
// als er serial data is, lees dit
while (Serial.available() > 0) {
int green = Serial.parseInt();
int blue = Serial.parseInt();
int red2 = Serial.parseInt();
if (Serial.read() == '\n') {
green = constrain(green, 0, 255);
blue = constrain(blue, 0, 255);
red2 = constrain(red2, 0, 255);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
analogWrite(redPin2, red2);
}
}
}
float getTemp(){
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return -100;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for (int i = 0; i < 9; i++) {
data
= ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB <<
| LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;}
void serialEvent()
{
serialA = Serial.read();
}
thanks for helping