Okay hey guys,
I'm currently using a Stellaris Launchpad (It's similar to Arduino)
I'm using the software called Energia to program it pretty much exactly like the Arduino.
My current code is this:
int redLED = RED_LED;
int greenLED = GREEN_LED;
int blueLED = BLUE_LED;
int Time = 30;
const int buttonINC = PUSH1;
const int buttonDEC = PUSH2;
int buttonIState = 0;
int buttonDState = 0;
void setup() {
pinMode(buttonINC, INPUT_PULLUP);
pinMode(buttonDEC, INPUT_PULLUP);
}
void checka() {
buttonIState = digitalRead(buttonINC);
if (buttonIState == HIGH) {
Time += 2;
}
}
void checkb() {
buttonDState = digitalRead(buttonDEC);
if (buttonDState == HIGH) {
Time -= 2;
}
}
void check() {
checka();
checkb();
if(Time < 1)
{
Time = 2;
}
}
void loop() {
check();
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(redLED, fadeValue);
delay(Time);
}
check();
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(redLED, fadeValue);
delay(Time);
}
check();
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(greenLED, fadeValue);
delay(Time);
}
check();
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(greenLED, fadeValue);
delay(Time);
}
check();
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(blueLED, fadeValue);
delay(Time);
}
check();
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
analogWrite(blueLED, fadeValue);
delay(Time);
}
}
PUSH1, PUSH2 are the built in buttons on the board.
RED_LED,GREEN_LED,BLUE_LED are used when using the RGB LED built onto the board.
Other then that it's mostly like the Arduino when it comes to the code, I am not the best at this language and I'm working my best to make the most cleanest and efficient code.
Basically what this does is it fades in Red, then fades out, fades in green, fades out green, fades in blue, fades out blue, and repeats, I can use the 2 buttons to change the speeds...
Also I was wondering if it was possible to make a interrupt sorta thing, where the button update are pretty much instant, like I don't have to wait for it to be checked it will change the speed automatically, hope you guys can help, if you need any more info just ask, I appreciate the help very much!