Hi, i start this topic because i can´t combine two programs. I want to use one or another program by pressing a button.
here are the two programs:
#include <LiquidCrystal.h>
//speciale caracters
byte p3[8] = {
B11111,
B00000,
B10000,
B10000,
B10000,
B10000,
B00000,
B11111
};
byte p4[8] = {
B11111,
B00000,
B11000,
B11000,
B11000,
B11000,
B00000,
B11111
};
byte p5[8] = {
B11111,
B00000,
B11100,
B11100,
B11100,
B11100,
B00000,
B11111
};
byte p6[8] = {
B11111,
B00000,
B11110,
B11110,
B11110,
B11110,
B00000,
B11111
};
byte p7[8] = {
B11111,
B00000,
B11111,
B11111,
B11111,
B11111,
B00000,
B11111
};
byte L[8] = {
B11111,
B00000,
B11111,
B10000,
B10000,
B10000,
B00000,
B11111
};
byte R[8] = {
B11111,
B00000,
B11111,
B00101,
B00101,
B11010,
B00000,
B11111
};
byte K[8] = {
B11100,
B11110,
B11111,
B11111,
B11111,
B11111,
B11110,
B11100
};
byte LEEG[8] = {
B11111,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B11111
};
int leftChannel = 0; // linker kanaal input
int rightChannel = 0; // rechter kanaal input
int left,left2,right,right2; //variabelen
const int numReadings = 3; //5 lezingen voor data
int readings[numReadings]; // aantal lezingen
int index = 0; // index van de momentele lezing
int total= 0; //totaal op nul zetten
int maxi=0;
int index2 = 0; // index van de momentele lezing (2)
int total2= 0; // hoogste getal in de lezingen
int maxi2=0;
int inputPin = A2; //ingangspin links
int inputPin2 = A4; //ingangspin rechts
int volL=0;
int volR=0;
int carL=0;
int carR=0;
int vul;
int vul2;
int laad;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //lcd configuratie
void setup() {
Serial.begin(9600);
lcd.begin(16, 2); //bepaling grootte van de lcd
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
lcd.createChar(1, p3);
lcd.createChar(2, p4);
lcd.createChar(3, p5);
lcd.createChar(4, p6);
lcd.createChar(5, p7);
lcd.createChar(6, L);
lcd.createChar(7, R);
lcd.createChar(8, K);
lcd.createChar(9, LEEG);
for(vul=0;vul<80;vul++)
{
for(laad=0;laad<vul/5;laad++)
{
lcd.setCursor(laad, 1);
lcd.write(5);
}
if(laad<1)
{
lcd.setCursor(0, 1);
lcd.write(5);
}
lcd.setCursor(laad+1, 1);
lcd.write((vul-vul/5*5)+1);
for(laad=laad+2;laad<16;laad++)
{
lcd.setCursor(laad, 1);
lcd.write(9);
}
lcd.setCursor(0, 0);
lcd.print(“loading…”);
delay(50);
}
lcd.clear();
delay(500);
}
void loop()
{
lcd.setCursor(0, 0); //L en R worden op het scherm gezet
lcd.write(6);
lcd.setCursor(0, 1);
lcd.write(7);
lcd.setCursor(15, 0); //kapjes worden op het scherm gezet
lcd.write(8);
lcd.setCursor(15, 1);
lcd.write(8);
total=analogRead(inputPin);
if(total > maxi)
{
maxi=total;
}
index++;
if (index >= numReadings) //Na 5 lezingen gaan we naar 0
{
index = 0;
left=maxi;
maxi=0;
}
total2=analogRead(inputPin2);
if(total2 > maxi2)
{
maxi2=total2;
}
index2++;
if (index2 >= numReadings) //Na 5 lezingen gaan we naar 0
{
index2 = 0;
right=maxi2;
maxi2=0;
}
volR=right/3;
if(volR>14)
{
volR=14;
}
for(vul = 0 ; vul < volR ; vul++)
{
lcd.setCursor(vul+1, 1);
lcd.write(5);
}
for(vul = volR+1 ; vul < 15 ; vul++)
{
lcd.setCursor(vul, 1);
lcd.write(9);
}
volL=left/3;
if(volL>14)
{
volL=14;
}
for(vul2 = 0 ; vul2 < volL ; vul2++)
{
lcd.setCursor(vul2+1, 0);
lcd.write(5);
}
for(vul2 = volL+1 ; vul2 < 15 ; vul2++)
{
lcd.setCursor(vul2, 0);
lcd.write(9);
}
Serial.println(left);
}
and the second:
// include the library code:
#include <LiquidCrystal.h>;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int DHpin = 8;
byte dat[5];
byte read_data()
{ byte data;
for(int i=0; i<8; i++)
{ if(digitalRead(DHpin) == LOW)
{ while(digitalRead(DHpin) == LOW); //
delayMicroseconds(30); //
if(digitalRead(DHpin) == HIGH) data |= (1<<(7-i)); //
while(digitalRead(DHpin) == HIGH); //
}
}
return data;
}
void start_test()
{
digitalWrite(DHpin,LOW); //
delay(30); //
digitalWrite(DHpin,HIGH);
delayMicroseconds(40); //
pinMode(DHpin,INPUT);
while(digitalRead(DHpin) == HIGH);
delayMicroseconds(80); //
if(digitalRead(DHpin) == LOW);
delayMicroseconds(80); //
for(int i=0;i<4;i++) //
dat = read_data();
pinMode(DHpin,OUTPUT);
digitalWrite(DHpin,HIGH); //
}
void setup() {
// set up the LCD’s number of columns and rows:
//Serial.begin(9600);
pinMode(DHpin,OUTPUT);
lcd.begin(16, 2);
// Print a message to the LCD.
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
start_test();
Serial.print("Current humdity = ");
Serial.print(dat[0], DEC); //
Serial.print(’.’);
Serial.print(dat[1],DEC); //
Serial.println(’%’);
Serial.print("Current temperature = ");
Serial.print(dat[2], DEC); //
Serial.print(’.’);
Serial.print(dat[3],DEC); //
Serial.println(‘C’); delay(700);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(dat[2]);
lcd.print(".");
lcd.print(dat[3]);
lcd.print(“C”);
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("Humedad: ");
lcd.print(dat[0]);
lcd.print(".");
lcd.print(dat[1]);
lcd.print("%");
}
Thank you!!