11 years, 8 months ago.

Is this program convenient for this project?

  1. include "mbed.h"

DigitalOut myled1(p5,p6); DigitalOut myled2(p7,p8); DigitalOut myled3(p9,p10); DigitalOut myled4(p11,p12); DigitalOut myled5(p13,p14); DigitalOut myled6(p15,p16);

DigitalIn pb1(p26); DigitalIn pb2(p25); DigitalIn pb3(p24); DigitalIn pb4(p23); DigitalIn pb5(p22); DigitalIn pb6(p21);

int main() { pb1.mode(pushdown); while(1) { myled1 = pb1;

} pb2.mode(pushdown); while(1){ myled2 = pb2; } pb3.mode(pushdown); while(1){

myled3 = pb3; } pb4.mode(pushdown); while(1){ myled4 = pb4; } pb5.mode(pushdown); while(1){ myled5 = pb5; } pb6.mode(pushdown) while(1){ myled6 = pb6; } }

/media/uploads/sanadjaradat92/wda.png

3 Answers

11 years, 8 months ago.

First of all, it is easier to read the code for people if you place the code in <<code title=Title>> CODE HERE <</code>> blocks.

Second of all, there are quite some errors in this code. Wich, as previously said, the compiler would have told you if you had compiled (or build) your project by pressing the 'compile' button (or just build by pressing CTRL-B).

The errors:

  • The DigitalOut class only accepts one argument, a PinName (see DigitalOut). In your case you provided two arguments (2 PinNames), but this is not the way to group output pins.
  • As said before, the mode 'pushdown' does not exist. This should probably be 'PullDown' (Note: case sensitive!) (see DigitalIn mode method)
  • A while(1) loop will NEVER end, this is an infinite loop. So when the program reaches the first while loop, it will never reach the second (or third, or fourth, etc) while loop. You could place all the 'myled# = pb#' assignments in ONE while loop to fix this.

Code

#include "mbed.h"

DigitalOut myled1(p5,p6); // This does not work 
DigitalOut myled2(p7,p8); 
DigitalOut myled3(p9,p10); 
DigitalOut myled4(p11,p12); 
DigitalOut myled5(p13,p14); 
DigitalOut myled6(p15,p16);

/* This should be something like this:
DigitalOut myled1(p5);
DigitalOut myled2(p6);
...
DigitalOut myled12(p16);
*/


DigitalIn pb1(p26); 
DigitalIn pb2(p25); 
DigitalIn pb3(p24); 
DigitalIn pb4(p23); 
DigitalIn pb5(p22); 
DigitalIn pb6(p21);

int main() { 
pb1.mode(pushdown); // pushdown should probably be PullDown
while(1) { myled1 = pb1; } 

// The program will never reach the following code because of the 'while(1) { myled1 = pb1; }' loop
pb2.mode(pushdown); 
while(1){ myled2 = pb2; } 

pb3.mode(pushdown); 
while(1){ myled3 = pb3; } 

pb4.mode(pushdown); 
while(1){ myled4 = pb4; } 

pb5.mode(pushdown); 
while(1){ myled5 = pb5; } 

pb6.mode(pushdown) 
while(1){ myled6 = pb6; } 

/* A solution to the while loop problem could be this:
while(1){
// group 1
myled1 = pb1;
myled2 = pb1;
// group 2
myled3 = pb2;
myled4 = pb3;
...
// group 6
myled11 = pb6;
myled12 = pb6;
}
*/
}

Regards,

Koen

Accepted Answer

thank u Mr. Groener ^_^

posted by sanad jaradat 31 Jan 2014
11 years, 8 months ago.

Did you ask the compiler? My humble answer is NO. Otherwise nice picture.

DigitalOut has only one parameter. Maybe BusOut.

Comparison in C or C++ is ==, not =.

There is no such parameter as pushdown. Maybe PullDown, PullUp, PullNone or OpenDrain.

Too many missing ;'s

Lot to read.

Regards.

11 years, 8 months ago.

thank you ^_^