// Dosya adı: LDR.ino
#include <PWM.h>//eklendi
int led = 9; // eklendi
int32_t frequency = 50; //eklendi frequency (in Hz)
#define button 3
#define inPin0// giriş A0 pini
#define LED1 4
#define LED2 5
#define LED3 6
#define LED4 7
#define LED5 8
#define LED6 10
#define LED7 11
void setup() {
pinMode(led,OUTPUT);
pinMode (button,INPUT);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode (LED1,OUTPUT);
pinMode (LED2,OUTPUT);
pinMode (LED3,OUTPUT);
pinMode (LED4,OUTPUT);
pinMode (LED5,OUTPUT);
pinMode (LED6,OUTPUT);
pinMode (LED7,OUTPUT);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED6,LOW);
int state = 0;
int old=0;
int buttonPoll=0;
int pwm_acik=0;
int isik=analogRead(A0);
Serial.begin(9600);
Serial.println(isik);
}
void loop() {
buttonPoll =digitalRead(button);
if (buttonPoll ==1){
delay(50);
buttonPoll=digitalRead(button);
if (buttonPoll ==0){
state =old+1;
}
}
else{
delay(100);
}
isik=analogRead(A0);
if(isik>50){
pwm_acik=1;
}
else{
pwm_acik=0;
digitalWrite(led,LOW);
}
switch (state){
case 1:
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
if(pwm_acik)
{
pwmWrite(led, 26);
}
old=state;
break;
case 2:
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
//pwmWrite(led, 44);
if(pwm_acik)
{
pwmWrite(led, 51);
}
old=state;
break;
case 3:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
//pwmWrite(led, 48);
if(pwm_acik)
{
pwmWrite(led, 76);
}
pwmWrite(led, 76);
old=state;
break;
case 4:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
//pwmWrite(led, 52);
pwmWrite(led, 102);
old=state;
break;
case 5:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
//pwmWrite(led, 58);
if(pwm_acik)
{
pwmWrite(led, 127);
}
old=state;
break;
case 6:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,HIGH);
digitalWrite(LED7,LOW);
//pwmWrite(led, 62);
if(pwm_acik)
{
pwmWrite(led, 153);
}
old=state;
break;
case 7:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,HIGH);
//pwmWrite(led, 78);
if(pwm_acik)
{
pwmWrite(led, 179);
}
old=state;
break;
default:
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
old=0;
break;
}
}