Day17
const int LEDPIN = 13;
int LEDSTATE = LOW;
unsigned long previousMillis = 0;
const long interval = 800;
void setup() {
pinMode(LEDPIN, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (LEDSTATE == LOW)
{
LEDSTATE = HIGH;
} else
{
LEDSTATE = LOW;
};
digitalWrite(LEDPIN, LEDSTATE);
}
}
the code didn't work as it didn't compile.
const int Button_int =0;
const int RED = 11;
const int GREEN = 10;
const int BLUE = 9;
boolean lastButtenstate = LOW;
volatile int selectedLED = RED;
void setup() {
pinMode(RED ,OUTPUT);
pinMode(GREEN ,OUTPUT);
pinMode(BLUE ,OUTPUT);
attachInterrupt(Button_int, swap, RISING);
}
void swap()
{
analogWrite(selectedLED, 0);
if(selectedLED == GREEN)
selectedLED = RED;
else if(selectedLED == RED)
selectedLED = BLUE;
else if(selectedLED == BLUE)
selectedLED = GREEN;
}
boolean debounce()
{
boolean Current = digitalRead(Button_int);
if (Current === HIGH)
{ Delay(50);
Current = digitalRead(Button_int);
Current = HIGH;
}
}
void loop()
{
for (int i=0; i <256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for(int i = 255; i >=0; i--)
analogWrite(selectedLED, i);
delay(10);
}
this is the one with the lights changing. it did work and changed lights with teh interupts
unsigned long previousMillis = 0;
const long interval = 800;
void setup() {
pinMode(LEDPIN, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (LEDSTATE == LOW)
{
LEDSTATE = HIGH;
} else
{
LEDSTATE = LOW;
};
digitalWrite(LEDPIN, LEDSTATE);
}
}
the code didn't work as it didn't compile.
const int Button_int =0;
const int RED = 11;
const int GREEN = 10;
const int BLUE = 9;
boolean lastButtenstate = LOW;
volatile int selectedLED = RED;
void setup() {
pinMode(RED ,OUTPUT);
pinMode(GREEN ,OUTPUT);
pinMode(BLUE ,OUTPUT);
attachInterrupt(Button_int, swap, RISING);
}
void swap()
{
analogWrite(selectedLED, 0);
if(selectedLED == GREEN)
selectedLED = RED;
else if(selectedLED == RED)
selectedLED = BLUE;
else if(selectedLED == BLUE)
selectedLED = GREEN;
}
boolean debounce()
{
boolean Current = digitalRead(Button_int);
if (Current === HIGH)
{ Delay(50);
Current = digitalRead(Button_int);
Current = HIGH;
}
}
void loop()
{
for (int i=0; i <256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for(int i = 255; i >=0; i--)
analogWrite(selectedLED, i);
delay(10);
}
this is the one with the lights changing. it did work and changed lights with teh interupts

Comments
Post a Comment