Witam chcę połączyć dwa projekty w jeden bardziej skomplikowany. Oba wykorzystują technologię Arduino Uno Grove i pierwszy ma w zestawie wyświetlacz LCD, czujnik temperatury i na ekranie wyświetlana jest ta temperatura.Drugi ma w zestawie czujnik światła i i LCD i na wyświetlaczy wyświetla natężenie światła. Chcę połączyć dwa projekty w jedną całość i żeby przyciskiem przełączać między tymi dwoma projektami. Więc zamieszczam tutaj kod projektu 1, kod projektu 2 i czysty program dla przycisku.Czysty kod dla przycisku dotyczy diod więc trzeba go też przerobić.Jeżeli ktoś mógłby doradzić albo pokazać jak to połączyć byłbym bardzo wdzięczny! z góry dziękuję za pomoc ;D
PROJEKT 1: temperatura
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("Temperatura!");
delay(1000);
}
float temperature;
int B=3975; //B value of the thermistor
float resistance;
void loop()
{
int a=analogRead(0);
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(temperature);
delay(100);
}
PROJEKT 2: czujnik światła
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
int sensorPin=A1;
double sensorvalue;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
Serial.begin(9600);
// Print a message to the LCD.
lcd.print("Czujnik swiatla!");
delay(1000);
}
float temperature;
int B=3975; //B value of the thermistor
float resistance;
void loop()
{
int a=analogRead(0);
lcd.setCursor(0, 1);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
sensorvalue=analogRead(sensorPin);
// print the number of seconds since reset:
lcd.print(sensorvalue);
lcd.setCursor(0, 0);
delay(100);
}
CZYSTY 3: button
// demo of Grove - Starter V2.0
// Loovee 2013-3-10
// this demo will show you how to use Grove - Button to control a LED
// when the button was pressed, the led will on
// otherwise led off
// Grove - Button connect to D3
// Grove - LED connect to D7
const int pinButton = 3; // pin of button define here
const int pinLed = 7; // pin of led define here
void setup()
{
pinMode(pinButton, INPUT); // set button INPUT
pinMode(pinLed, OUTPUT); // set led OUTPUT
}
void loop()
{
if (digitalRead(pinButton)) // when button is pressed
{
digitalWrite(pinLed, HIGH); // led on
}
else
{
digitalWrite(pinLed, LOW);
}
delay(10);
}