well you are right i setting my digital pins to HIGH before setting them to OUTPUT
because i copy it from the original code
this the original code :
int sw1 = 0; int sw11 = 0; int sw21 = 0;
int sw2 = 0; int sw12 = 0; int sw22 = 0;
int sw3 = 0; int sw13 = 0; int sw23 = 0;
int sw4 = 0; int sw14 = 0; int sw24 = 0;
int sw5 = 0; int sw15 = 0; int sw25 = 0;
int sw6 = 0; int sw16 = 0; int sw26 = 0;
int sw7 = 0; int sw17 = 0; int sw27 = 0;
int sw8 = 0; int sw18 = 0; int sw28 = 0;
int sw9 = 0; int sw19 = 0; int sw29 = 0;
int sw10 = 0; int sw20 = 0; int sw30 = 0;
int sw31 = 0; int sw41 = 0; int sw51 = 0;
int sw32 = 0; int sw42 = 0; int sw52 = 0;
int sw33 = 0; int sw43 = 0; int sw53 = 0;
int sw34 = 0; int sw44 = 0;
int sw35 = 0; int sw45 = 0;
int sw36 = 0; int sw46 = 0;
int sw37 = 0; int sw47 = 0;
int sw38 = 0; int sw48 = 0;
int sw39 = 0; int sw49 = 0;
int sw40 = 0; int sw50 = 0;
void setup() {
pinMode(22, OUTPUT); pinMode(32, OUTPUT); pinMode(42, OUTPUT); pinMode(52, OUTPUT);
pinMode(23, OUTPUT); pinMode(33, OUTPUT); pinMode(43, OUTPUT); pinMode(53, OUTPUT);
pinMode(24, OUTPUT); pinMode(34, OUTPUT); pinMode(44, OUTPUT);
pinMode(25, OUTPUT); pinMode(35, OUTPUT); pinMode(45, OUTPUT);
pinMode(26, OUTPUT); pinMode(36, OUTPUT); pinMode(46, OUTPUT);
pinMode(27, OUTPUT); pinMode(37, OUTPUT); pinMode(47, OUTPUT);
pinMode(28, OUTPUT); pinMode(38, OUTPUT); pinMode(48, OUTPUT);
pinMode(29, OUTPUT); pinMode(39, OUTPUT); pinMode(49, OUTPUT);
pinMode(30, OUTPUT); pinMode(40, OUTPUT); pinMode(50, OUTPUT);
pinMode(31, OUTPUT); pinMode(41, OUTPUT); pinMode(51, OUTPUT);
digitalWrite(22, HIGH); digitalWrite(32, HIGH); digitalWrite(42, HIGH); digitalWrite(52, HIGH);
digitalWrite(23, HIGH); digitalWrite(33, HIGH); digitalWrite(43, HIGH); digitalWrite(53, HIGH);
digitalWrite(24, HIGH); digitalWrite(34, HIGH); digitalWrite(44, HIGH);
digitalWrite(25, HIGH); digitalWrite(35, HIGH); digitalWrite(45, HIGH);
digitalWrite(26, HIGH); digitalWrite(36, HIGH); digitalWrite(46, HIGH);
digitalWrite(27, HIGH); digitalWrite(37, HIGH); digitalWrite(47, HIGH);
digitalWrite(28, HIGH); digitalWrite(38, HIGH); digitalWrite(48, HIGH);
digitalWrite(29, HIGH); digitalWrite(39, HIGH); digitalWrite(49, HIGH);
digitalWrite(30, HIGH); digitalWrite(40, HIGH); digitalWrite(50, HIGH);
digitalWrite(31, HIGH); digitalWrite(41, HIGH); digitalWrite(51, HIGH);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 1) {
int input = Serial.read() ;
Serial.println( input, DEC);
if (input == 'A') {
digitalWrite(22, sw1);
sw1 = !sw1;
}
if (input == 'B'){
digitalWrite(23, sw2);
sw2 = !sw2;
}
if (input == 'C'){
digitalWrite(24, sw3);
sw3 = !sw3;
}
if (input == 'D'){
digitalWrite(25, sw4);
sw4 = !sw4;
}
if (input == 'E'){
digitalWrite(26, sw5);
sw5 = !sw5;
}
if (input == 'F'){
digitalWrite(27, sw6);
sw6 = !sw6;
}
if (input == 'G'){
digitalWrite(28, sw7);
sw7 = !sw7;
}
if (input == 'H'){
digitalWrite(29, sw8);
sw8 = !sw8;
}
if (input == 'I'){
digitalWrite(30, sw9);
sw9 = !sw9;
}
if (input == 'J'){
digitalWrite(31, sw10);
sw10 = !sw10;
}
if (input == 'K'){
digitalWrite(32, sw11);
sw11 = !sw11;
}
if (input == 'L'){
digitalWrite(33, sw12);
sw12 = !sw12;
}
if (input == 'M'){
digitalWrite(34, sw13);
sw13 = !sw13;
}
if (input == 'N'){
digitalWrite(35, sw14);
sw14 = !sw14;
}
if (input == 'O'){
digitalWrite(36, sw15);
sw15 = !sw15;
}
if (input == 'P'){
digitalWrite(37, sw16);
sw16 = !sw16;
}
if (input == 'Q'){
digitalWrite(38, sw17);
sw17 = !sw17;
}
if (input == 'R'){
digitalWrite(39, sw18);
sw18 = !sw18;
}
if (input == 'S'){
digitalWrite(40, sw19);
sw19 = !sw19;
}
if (input == 'T'){
digitalWrite(41, sw20);
sw20 = !sw20;
}
if (input == 'U'){
digitalWrite(42, sw21);
sw21 = !sw21;
}
if (input == 'V'){
digitalWrite(43, sw22);
sw22 = !sw22;
}
if (input == 'W'){
digitalWrite(44, sw23);
sw23 = !sw23;
}
if (input == 'X'){
digitalWrite(45, sw24);
sw24 = !sw24;
}
if (input == 'Y'){
digitalWrite(46, sw25);
sw25 = !sw25;
}
if (input == 'Z'){
digitalWrite(47, sw26);
sw26 = !sw26;
}
if (input == '1'){
digitalWrite(48, sw27);
sw27 = !sw27;
}
if (input == '2'){
digitalWrite(49, sw28);
sw28 = !sw28;
}
if (input == '3'){
digitalWrite(50, sw29);
sw29 = !sw29;
}
if (input == '4'){
digitalWrite(51, sw30);
sw30 = !sw30;
}
if (input == '5'){
digitalWrite(52, sw31);
sw31 = !sw31;
}
if (input == '6'){
digitalWrite(53, sw32);
sw32 = !sw32;
}
}
}