Help writing code for metro

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Proteus1985
 
Posts: 24
Joined: Thu Mar 07, 2019 7:39 am

Help writing code for metro

Post by Proteus1985 »

Hi guys, need some more help from you very talented people.

I’m trying to learn code to program my metro board and I just can’t seem to get my head round it, or at least it’s very slow.

I was wondering if I was to wright out the sequence I’m trying to achieve if anyone out there could point me in the right direction, please.

Here’s how I would like the program to run.

When switched on at first, 2 green leds comes on. (Start of the program)

Next there’s a break in the circuit (I intend to use a simple widow alarm switch, a door opens causing the circuit to break)

The green led lights go out. 2 white leds come on. And one red led comes on.

Next the break in the circuit is rejoined (door closes) the 2 white leds go off. Red led stays on.

Nothing else happens at this point.

Next a button is pushed and another red led come on ( at this point 2 red leds are on)

Next another button is pushed, 1 red led goes off, the other red led stays on( the red that’s been on from previous) 1 yellow led comes on.

Next another button is pushed, the red led goes off and the yellow, and the 2 green leds from the beginning comes back on. And then the cycle would repeat, open door, close door, push buttons

That probably sounds really confusing but if any one could give me any idea how that is written in code I would be extremely great full

Thank you in advanced

User avatar
kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help writing code for metro

Post by kcl1s »

Which Metro do you have and what code language you will be using?

The way you described the sequence is helpful. Each step has its own outputs and an input that will take it to the next step. I would use a variable that denotes what step you are on. Then have your code do only the section of code for that step and increment the step variable when the right input is detected. If you are using Arduino code the switch / case commands would work best. https://www.arduino.cc/reference/en/lan ... witchcase/

Fellow hobbyist
Keith

User avatar
Proteus1985
 
Posts: 24
Joined: Thu Mar 07, 2019 7:39 am

Re: Help writing code for metro

Post by Proteus1985 »

Hi Keith

Thank your for responding, the metro I’m using is the M0 express.

The program I will use for the code willl be the same one that adafruit used for there online tutorials, of which I’m only a few in and still very confused by it all

User avatar
kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help writing code for metro

Post by kcl1s »

The Metro M0 Express can be coded in at least 3 languages. Can you link to the tutorials you are using?

Keith

User avatar
Proteus1985
 
Posts: 24
Joined: Thu Mar 07, 2019 7:39 am

Re: Help writing code for metro

Post by Proteus1985 »

Making my way through these slowly lol

https://learn.adafruit.com/experimenter ... -for-metro

User avatar
kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help writing code for metro

Post by kcl1s »

So you are using the Arduino language. Great. So I need to know where you are in your knowledge. In that guide the program you described above is really only using circ01 and circ07. Have you gone over them and understand them? Do you understand how make a pin an output? Do you understand that variable names for pin numbers can be helpful for following the program flow?

When you think you got the above you can begin your code. The best way is to break it down in small steps. Start with
When switched on at first, 2 green leds comes on. (Start of the program)
Wire and program that to get started. Then we look for the door opening. This is a great place for a while loop https://www.arduino.cc/reference/en/lan ... ure/while/. Basically you make the while loop so it does nothing until the door opens. Something like this while(digitalRead(doorSwitch) == HIGH) {}. Then you continue with the outputs you want on the second step.

Give that a try and post your code (between code tags using the button above the edit window) and any questions you have.

Keith

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”