I have made this code to make night and day over my model railroad.
But I witch to jumb a code over, but just ones.
The code i wish to jumb over is this?
}
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
}
I know I maybe can do this wtih an if, but I do not know how to make an Subtraction so x is equal to y
if (x == 1)
{
}
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
}
}
like x= 2 - 1; so I can use it in the if command...
if (x == 1)
{
}
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
}
}
Okay here all my code, and the part I wich to jumb over is the code under the firs //white fluorescent lamp
#define LEDW 9 // the pin for the white fluorescent lamp
#define LEDO 10 // the pin for the Orange fluorescent lamp
#define LEDB 11 // the pin for the blue fluorescent lamp
int i = 0; // We'll use this to count up and down
void setup() {
pinMode(LEDW, OUTPUT); // tell Arduino white fluorescent lamp is an output
pinMode(LEDO, OUTPUT); // tell Arduino Orange fluorescent lamp is an output
pinMode(LEDB, OUTPUT); // tell Arduino blue fluorescent lamp is an output
}
void loop(){
//Go from day to night
//Orange fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
int x
x = -10;
x = x - 1; // x now contains 9 - rolls over in neg. direction
if (x==8)
{
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
}
}
//blue fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDB, i); // set the blue fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//Orange fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms
}
//Go from night to day
//Orange fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//blue fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDB, i); // set the blue fluorescent lamp brightness
delay(10); // Wait 10ms
}
//white fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//Orange fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms
}
}
I can´t get x to be 8. I have never trid to work with subtraction
The code that follows this unconditionally varies the intensity of the LED from 0 to 255.
The code you want to make conditionally executed does the same, except for varying the value for a different pin.
You have not explained what the condition should be. Rather than trying to explain it in terms of code, explain it in terms of physical conditions - daytime, nighttime, there is a train present, etc.
Then, explain how you (will) know that the condition is, or is not, true. If the code is to be skipped, for instance, when it is daytime, you need to know what time it is or you need to know how light it is.
Once we know what condition must be true, and how to determine whether or not that condition is true, we can help you with the if statement.
The code works, but to work perfectly I need to jumb over the code here.
But how to do it I do not know...
I maybe have to use if (conditional) like if (x==y) then execute the code. But the first time (x must not be equal to y) only the second time and forever.
But I also see another problem because the third time(x will again not be equal to y)
I can´t see how to jumb over the code only the first time and then never again.
}
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
}
Okay thats sound good PaulS and i put that in my code, but now I have a expected ´}` at end of input
#define LEDW 9 // the pin for the white fluorescent lamp
#define LEDO 10 // the pin for the Orange fluorescent lamp
#define LEDB 11 // the pin for the blue fluorescent lamp
int i = 0; // We'll use this to count up and down
void setup() {
pinMode(LEDW, OUTPUT); // tell Arduino white fluorescent lamp is an output
pinMode(LEDO, OUTPUT); // tell Arduino Orange fluorescent lamp is an output
pinMode(LEDB, OUTPUT); // tell Arduino blue fluorescent lamp is an output
}
void loop(){
//Go from day to night
//Orange fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
boolean skipMe = true;
if(skipMe)
{
skipMe = false;
}
else
{
//white fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms
{
}
//blue fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDB, i); // set the blue fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//Orange fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms
}
//Go from night to day
//Orange fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//blue fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDB, i); // set the blue fluorescent lamp brightness
delay(10); // Wait 10ms
}
//white fluorescent lamp
for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
analogWrite(LEDW, i); // set the white fluorescent lamp brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
//Orange fluorescent lamp
for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)
analogWrite(LEDO, i); // set the Orange fluorescent lamp brightness
delay(10); // Wait 10ms
}
}