Well i am using some mosfet shield and the pwm signals
the idea i have is that one signal over serial will controll the light behaviour of 6 pwm pins ( 3 5 6 9 10 11)
The code accepts input as from 0 to 65 to dim leds this works nice
However i also wanted to create a slow blinking led, codes input 66 to 71 (slow) input (72 to 77) faster and input 78 to 83 fastest
i 've been looking over it for some hours nows but i dont see whats wrong here, is there perhaps a limit on the arduino ??
Here below is the complete code:
int pwmport = 0;
int pwmval = 0;
//char input = 66;
int input =0;
int pwmpin[]={3,5,6,9,10,11 }; //an array is a collection of nummer in this case pwm pins of arduino
int mode[] ={0,0,0,0,0,0};
int counter = 0;
void setup()
{
// >> see switch mode function
Serial.begin(57600);
}
void loop()
{
// input= Serial.read();
// serial.println(i)
input = 79; // THIS EQUALS SET PWM PIN 11 in BLINK MODE
pwmport = input % 6;
if ( input<66)
{ pwmval = input * 10 / 6;
analogWrite ( pwmpin[pwmport],pwmval );
mode[pwmport] = 0; }
Serial.print ("set pin ");
Serial.print(pwmport);
Serial.print(" in mode ");
if ((input>65)&&(input<72)){ mode[pwmport] = 1;Serial.println(1);}
if ((input>71)&&(input<78)) {mode[pwmport] = 2;Serial.println(2);}
if ((input>77)&&(input<84)) {mode[pwmport] = 3;Serial.println(3);}
++counter;
for (int i=0;i<6;i++)
{ Serial.print("pin ");
Serial.print(i);
Serial.print(" mode=");
Serial.print(mode[i]);Serial.print(" ");
Serial.print("value=" );
Serial.println(abs( -255 + (counter % 510 )));
switch (mode[i]) // i is the pin mode[i] is the mode for that pin
{
case 0:
; // do nothing it is handled above
break;
case 1:
analogWrite (i , abs( -255 + (counter *1 % 510 )));
break;
case 2:
analogWrite(i , abs( -255 + ((counter * 2 ) % 510 )));
break;
case 3:
analogWrite(i , abs( -255 + ((counter * 4 ) % 510 )));
break;
default:
Serial.print("Error");
}
}
delay(1000); // 1 second
}