DenyX:
Do you like this program should look like ??
There is a lot to comment on. But everybody has to start somewhere.
I think your durations are a bit off. From the opening post, I understand that you have a total duration of 800ms; all your delays total to 5600ms.
But OK, you can now take it to the next level
As you can see, you do the same 'thing' time after time; switch LED on or off, wait a while, switch the LED on or off, wait a while, .....
This screams for the use of a function. Read up on them. A simple function could be
/*
switch LED on or off for given time
*/
void doLed(int state, unsigned long duration)
{
// set LED to given state
digitalWrite(led, state);
// delay for given duration
delay(duration);
}
You can call this from loop() a number of times. Not perfect for the given homework as the approach should be a little different but it will do the job.
Next you might want to rethink the approach. You have a bit pattern that needs to be reflected by the LED (like in serial communications). So the duration in the above code is basically fixed (like the baudrate on a serial port).
The below is a slightly simpler function with a fixed duration of 100ms
void displayBit(int bitValue)
{
// display bit
digitalWrite(led, bitValue);
// delay 100ms
delay(100);
}
For every bit that you need to display, you call this function. So in the loop(), you call displayBit() 8 times with the appropriate bit value (LOW or HIGH, 0 or 1).
void loop()
{
displayBit(LOW); // display first bit
displayBit(HIGH);
displayBit(LOW);
displayBit(LOW);
displayBit(LOW);
displayBit(HIGH);
displayBit(LOW);
displayBit(HIGH); // display last bit
}
Note: this might be too advanced for your homework; so be careful what you submit
There are a few more steps that you can take. E.g. using a byte to store the data pattern and looping through the bits (e.g. with a for loop) and call displayBit based on the bit in the data pattern.
A note on the delay (just to keep JimboZA happy ). The total cycle that you posted takes 5.6 seconds. What if you need to be able to interrupt the cycle at anytime using e.g. a button. You press the button and next you have to wait up to 5.6 seconds before the code can detect that the button was pressed.
The IDE comes with a BlinkWithoutDelay example; there is also a post here called several things at a time. Go through them, understand what they do and why they do what they do.