int MaxRead=50;
const int MaxFunc=3;
byte LastKey=0;
int KeyCount=0;
int Bright=127;
byte flashState=0;
byte Funkce=1;
void setup() {
// put your setup code here, to run once:
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
void ON()
{
analogWrite(10,Bright);
analogWrite(11,Bright);
}
void OFF()
{
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
void Flash01()
{
digitalWrite(10,flashState);
digitalWrite(11,flashState);
MyDelay(200);
flashState=!flashState;
}
void Flash02()
{
digitalWrite(10,flashState);
digitalWrite(11,!flashState);
MyDelay(200);
flashState=!flashState;
}
byte ReadKey()
{
byte key=0;
byte ReturnKey=0;
if (!digitalRead(4)) {key=1;}
if (!digitalRead(3)) {key=2;}
if (!digitalRead(2)) {key=3;}
delay(10);
if (key)
{
if (LastKey==key)
{
KeyCount++;
}
else
{
LastKey=key;
KeyCount=0;
}
}
if (KeyCount>MaxRead)
{
ReturnKey=key;
KeyCount=0;
}
return ReturnKey;
}
void SetFunction()
{
byte KeyRead=ReadKey();
switch (KeyRead)
{
case 1:
{
Funkce--;
if (Funkce<1)
{
Funkce=4;
}
break;
}
case 2:
{
Funkce++;
if (Funkce>4)
{
Funkce=1;
}
break;
}
case 3:
{
Bright=Bright+64;
if (Bright>255)
{
Bright=63;
}
break;
}
}
}
void MyDelay(int del)
{
SetFunction();
delay(del);
}
void loop()
{
// put your main code here, to run repeatedly:
SetFunction();
switch (Funkce)
{
case 1:
{
MaxRead=50;
OFF();
break;
}
case 2:
{
MaxRead=50;
ON();
break;
}
case 3:
{
MaxRead=10;
Flash01();
break;
}
case 4:
{
MaxRead=10;
Flash02();
break;
}
}
}