8 years, 1 month ago.

adapted Arduino program MBED

  1. include <SPI.h>
  1. define DATA_PIN 11
  2. define CLK_PIN 13
  3. define LATCH_PIN 8

void setup() { set the LATCH_PIN as an output: pinMode (LATCH_PIN, OUTPUT); initialize SPI: SPI.begin(); Autre init SPI à prevoir ? }

void loop() {

byte rouge[8] ={B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000};

byte vert[8] ={ B00010000, B00110000, B01111111, B11111111, B01111111, B00110000, B00010000, B00000000};

byte bleu[8] ={B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000};

byte anode = {B00000000};

for (int i = 0; i <8 ; i++) {

digitalWrite(LATCH_PIN, LOW);

send in the address and value via SPI:

Colonne 1,2,3 en bleu

SPI.transfer(bleu[i]);B

SPI.transfer(vert[i]);G

SPI.transfer(rouge[i]);R

switch (i)

{

case (0):

anode = B00000001 ;

break;

case (1):

anode = B00000010 ;

break;

case (2):

anode = B00000100 ;

break;

case (3):

anode = B00001000 ;

break;

case (4):

anode = B00010000 ;

break;

case (5):

anode = B00100000 ;

break;

case (6):

anode = B01000000 ;

break;

case (7):

anode = B10000000 ;

break;

} SPI.transfer(anode);Anode

take the SS pin high to de-select the chip:

digitalWrite(LATCH_PIN,HIGH);

delay(1); 1ms de pause avant envoy d'un autre message

} }

Can you help me to adapt the Arduino program MBED !! thank you very much

1 Answer

8 years, 1 month ago.

change the include at the start to

#include "mbed.h"

Change the pin number defines to

DigitalOut latchPin([IO pin]);  // replace [IO pin] with the correct pin name for the board you are using
SPI SpiBus([Out],[In],[Clk]); // replace [Out],[In] & [Clk] with the correct pin names

For the correct pin names check the diagram on your boards platform page.

At the end add:

main () {
  setup();
  while (true) {
    loop();
  }
}

You then need to change the appropriate function calls e.g. digitalWrite(LATCH_PIN,LOW); becomes latchPin = 0;

The SPI setup is: SpiBus.format([bits],[mode]) ; (try 8 bits mode 0 if you're not sure) SpiBus.frequency([rate in Hz]);

And an spi write is simply SpiBus.write([data]);

Also I don't know if this compiler likes the way some numbers are specified in binary. You may need to convert the numbers to hex e.g. 0x08 in place of B00001000.

Make those changes and have a go at fixing the remaining problems, I'm sure there will be some. If you can't figure them out from the documentation then ask again.

And when posting next time please use

<<code>>
your c code
<</code>>



so that the code is correctly formatted.