Ok im not going to lie i know absolutly nothing about C what so ever i bought the arduino well to learn but i think i jumped in head deep the project i want to do is pretty simple i want to control 120vac line with a transistor a diode and a resistor and a relay the project is already layed out here
glacialwanderer.com/hobbyrobotics/?p=9#comment-4891
the code is simple and i some what understand it what i want to be able to do is be able to control 2 or 3 or 4 relays to give you a visual idea of what i want is i want to be able to sit at my computer and open putty and open a connection to COM3 be Greated by Press 1 to toggle relay 1 press 2 to toggle relay 2 press 3 to toggle relay 3
then as i press 1 i want it to toggle one pin if i press 1 again i want it to toggle off and same for 2 and 3 on diffrent pins i know im asking to be spoon fed and im sorry but i was hoping some one might be able to mod the code for 1 more relay so i can get any idea how to add more i thank you for your help in advance as im simply lost
#define RELAY_PIN 3
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
Serial.begin(9600); // open serial
Serial.println("Press the spacebar to toggle relay on/off");
}
void loop()
{
static int relayVal = 0;
int cmd;
while (Serial.available() > 0)
{
cmd = Serial.read();
switch (cmd)
{
case ' ':
{
relayVal ^= 1; // xor current value with 1 (causes value to toggle)
if (relayVal)
Serial.println("Relay on");
else
Serial.println("Relay off");
break;
}
default:
{
Serial.println("Press the spacebar to toggle relay on/off");
}
}
if (relayVal)
digitalWrite(RELAY_PIN, HIGH);
else
digitalWrite(RELAY_PIN, LOW);
}
}