Hello,
I have a question about my project table and if the arduino mega would be able to handle it one way or another.
The table consists of 3 different sections that do different things using the arduino. At the moment I have code for all 3 seperatly and they work individually but I was not able to bring them together yet so they can work seperatly but into one code for the arduino.
Part 1 and 2 do seperatly for 2 different drawers: press touch sensor, arduino converts the signal into press on, press off and makes a motor run one way or another and control some RGB strips
Part 3 is a reed switch that if on controls a x10 module for my lights etc. and a different motorsetup for a beamerlift.
Code for part 1 and 2 is twice like this(but with different pins offcourse)
int i=0;
int a=0;
void setup()
{
pinMode(4, INPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT)
}
void loop()
{
if (i == 0){ digitalWrite(6, LOW);digitalWrite(8, LOW);} else{digitalWrite(6, HIGH);digitalWrite(8, HIGH);}
if (i == 0 && digitalRead(4) == HIGH && a == 1){i = 1;} else{} // LED moet aan
if (i == 1 && digitalRead(4) == HIGH && a == 0){i = 0;} else{} // LED moet uit
if (i == 0 && digitalRead(4) == LOW){a = 1;} else{} // Test LED=uit en S4 is losgelaten
if (i == 1 && digitalRead(4) == LOW){a = 0;} else{} // Test LED=aan en S4 is losgelaten
}
The other piece of code for part 3 is like this:
int switchPin = 2; // reed switch is connected to pin 2
int X10Pin = 12;
int MotorPin = 11;
int ledPin = 10;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState; // variable to hold the button state
int EntertainmentMode = 0;
void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(X10Pin, OUTPUT);
pinMode(MotorPin, OUTPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin); // read the initial state
}
void loop(){
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (EntertainmentMode == 0) {
EntertainmentmodeMode = 1;
digitalWrite(X10Pin, HIGH);
digitalWrite(MotorPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
EntertainmentMode = 0;
digitalWrite(X10Pin, LOW);
digitalWrite(MotorPin, LOW);
digitalWrite(ledPin, LOW);
}
}
}
buttonState = val; // save the new state in our variable
}
}
So now my question is how can I put all those things together so they can all work on one arduino? just throwing them together does not work i've noticed :~