Hi all.
This is my first post here. I am in need of some help. I done a small home automation using arduino duemilanove but this is not enough for me since I need more outputs. As I said, need of more outputs, I know that this could be solved by using 2 arduino communicating together but for now I went for the easy way, bought the Arduino Mega. I managed to finalize some coding with the help of google on the duemilanove but I found a problem when I tried to use the same coding for the Arduino Mega. What could be the problem?
In this Post I have included the open source programming of Arduino IDE and processing. If someone could point me out what could be the problem why Arduino Mega is not working with the same code I appreciate a lot.
Is there any other type of programming that I need to do?
Take a look below arduino IDE programming!
int message = 0; // This will hold one byte of the serial message
int redLEDPin = 13; // What pin is the red LED connected to?
int greenLEDPin = 12; // What pin is the green LED to?
int blueLEDPin = 11; // What pin is the blue LED to?
int yellowLEDPin = 10; // What pin is the yellow Led to?
int violetLEDPin = 9; // What pin is the violet Led to?
int redLED = 0; // The value/brightness of the LED, can be 0-255
int greenLED = 0; // The value brightness of the LED, can be 0-255
int blueLED = 0; // The value brightness of the LED, can be 0-255
int yellowLED = 0; // The value brightness of the LED, can be 0-255
int violetLED = 0; // The value brightness of the LED, can be 0-255
void setup() {
Serial.begin(9600); //set serial to 9600 baud rate
}
void loop(){
if (Serial.available() > 0) { // Check if there is a new message
message = Serial.read(); // Put the serial input into the message
if (message == 'R'){ // If a capitol R is received...
redLED = 255; // Set redLED to 255 (on)
}
if (message == 'r'){ // If a lowercase r is received...
redLED = 0; // Set redLED to 0 (off)
}
}
analogWrite(redLEDPin, redLED); // Write an analog value between 0-255
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'G'){ // If a capitol R is received...
greenLED = 255; // Set greenLED to 255 (on)
}
if (message == 'g'){ // If a lowercase r is received...
greenLED = 0; // Set greenLED to 0 (off)
}
analogWrite(greenLEDPin, greenLED); // Write an analog value between 0-255
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'B'){ // If a capitol R is received...
blueLED = 255; // Set blueLED to 255 (on)
}
if (message == 'b'){ // If a lowercase r is received...
blueLED = 0; // Set blueLED to 0 (off)
}
analogWrite(blueLEDPin, blueLED); // Write an analog value between 0-255
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'Y'){ // If a capitol R is received...
yellowLED = 255; // Set yellowLED to 255 (on)
}
if (message == 'y'){ // If a lowercase r is received...
yellowLED = 0; // Set yellowLED to 0 (off)
}
analogWrite(yellowLEDPin, yellowLED); // Write an analog value between 0-255
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'V'){ // If a capitol R is received...
violetLED = 255; // Set violetLED to 255 (on)
}
if (message == 'v'){ // If a lowercase r is received...
violetLED = 0; // Set violetLED to 0 (off)
}
analogWrite(violetLEDPin, violetLED); // Write an analog value between 0-255
}