Go Down

Topic: level crossing  (Read 114 times) previous topic - next topic

andrewfowler1

Apr 21, 2019, 10:05 am Last Edit: Apr 21, 2019, 12:43 pm by andrewfowler1
high guys newbie here,i would like to use this code but without the button, can i just remove any

reference to the button, the aim is to  get yellow led to come on for 1 sec then go off, then the 2 red flash opposite to each other for about 5 seconds  and repeat after 1 minute


Code: [Select]
const int RED1 = 12; // Left hand RED led
const int RED2 = 13; // Right hand RED led
const int YELLOW = 11; // Amber LED
const int TRACK = 8; //track interlock (train sensor)
int button = 0; //variable for reading track interlock input

void setup()
{
pinMode (RED1, OUTPUT);
pinMode (RED2, OUTPUT);
pinMode (YELLOW, OUTPUT);
pinMode (TRACK, INPUT);

}
void loop()
{

do {
  button = digitalRead(TRACK);  //read port 8 pushbutton
} while (button == LOW); // loop back whilst button is not pressed

 digitalWrite(YELLOW, HIGH); //put amber warning LED on for 3 sec
 delay (3000);
 digitalWrite(YELLOW, LOW);
 
 do {                         // Alternating RED LED sequence
 digitalWrite(RED1, HIGH);
 delay(1000);
 digitalWrite(RED1, LOW);
 digitalWrite(RED2, HIGH);
 delay(1000);
 digitalWrite(RED2, LOW);
 
 button = digitalRead(TRACK);  //read port 8 pushbutton
 } while (button == HIGH); //repeat while button is pressed
 delay (100); //wait 100 msec
}/code]

Paul__B

Got the square brackets wrong.

You need to go and read the forum instructions so that you can go back and modify your original posts - both of them - (and not re-post them) using the "More -> Modify" option below the right hand corner of your post to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.  But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code" it can frequently be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space.  Do use blank lines, but only between functional blocks.



That done, you need to examine the code and work through it in the way you expect to microcontroller to operate, and see what each part does.  Then you should have an idea of which part to modify.

Coding is based on understanding what the code is doing.  Once you understand it, you can do more things, so it is better to work that way than for someone just to modify it for you.

In particular, You need to explain why you want to "use this code but without the button"?

Go Up