Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:e4d483d82cd8, committed 2014-05-26
- Comitter:
- tim003
- Date:
- Mon May 26 12:29:55 2014 +0000
- Parent:
- 1:8186a841911c
- Child:
- 3:43648fa57d55
- Commit message:
- LukaIElmir2;
Changed in this revision
--- a/LEDMatrix.h Mon May 19 18:17:34 2014 +0000
+++ b/LEDMatrix.h Mon May 26 12:29:55 2014 +0000
@@ -4,4 +4,156 @@
#define LEDMatrix_h
+/*#include "LEDMatrix.h"
+
+//DigitalOut myled(LED1);
+AnalogIn pot(dp9);
+Serial pc(USBTX, USBRX);
+
+Ticker t;
+
+
+
+// p5: DIN, p7: CLK, p8: LOAD/CS
+SPI max72_spi(dp2, dp1, dp6);
+DigitalOut load(dp24); //Chip_Select
+
+int maxInUse = 1; //change this variable to set how many MAX7219's you'll use
+
+// define max7219 registers
+#define max7219_reg_noop 0x00
+#define max7219_reg_digit0 0x01
+#define max7219_reg_digit1 0x02
+#define max7219_reg_digit2 0x03
+#define max7219_reg_digit3 0x04
+#define max7219_reg_digit4 0x05
+#define max7219_reg_digit5 0x06
+#define max7219_reg_digit6 0x07
+#define max7219_reg_digit7 0x08
+#define max7219_reg_decodeMode 0x09
+#define max7219_reg_intensity 0x0a
+#define max7219_reg_scanLimit 0x0b
+#define max7219_reg_shutdown 0x0c
+#define max7219_reg_displayTest 0x0f
+
+#define LOW 0
+#define HIGH 1
+#define MHZ 1000000
+
+void maxSingle( int reg, int col) {
+//maxSingle is the "easy" function to use for a
+//single max7219
+ load = LOW; // begin
+ max72_spi.write(reg); // specify register
+ max72_spi.write(col); // put data
+ load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
+}
+
+void maxAll (int reg, int col) { // initialize all MAX7219's in the system
+ load = LOW; // begin
+ for ( int c=1; c<= maxInUse; c++) {
+ max72_spi.write(reg); // specify register
+ max72_spi.write(col); // put data
+ }
+ load = HIGH;
+}
+
+void maxOne(int maxNr, int reg, int col) {
+//maxOne is for adressing different MAX7219's,
+//while having a couple of them cascaded
+ int c = 0;
+ load = LOW;
+
+ for ( c = maxInUse; c > maxNr; c--) {
+ max72_spi.write(0); // no-op
+ max72_spi.write(0); // no-op
+ }
+
+ max72_spi.write(reg); // specify register
+ max72_spi.write(col); // put data
+
+ for ( c=maxNr-1; c >= 1; c--) {
+ max72_spi.write(0); // no-op
+ max72_spi.write(0); // no-op
+ }
+ load = HIGH;
+}
+
+
+void setup () {
+ // initiation of the max 7219
+ // SPI setup: 8 bits, mode 0
+ max72_spi.format(8, 0);
+
+ // going by the datasheet, min clk is 100ns so theoretically 10MHz should work...
+ // max72_spi.frequency(10*MHZ);
+
+ maxAll(max7219_reg_scanLimit, 0x07);
+ maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
+ maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode
+ maxAll(max7219_reg_displayTest, 0x00); // no display test
+ for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
+ maxAll(e,0);
+ }
+ maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
+ // range: 0x00 to 0x0f
+}
+
+void loop () {
+
+ //if you use just one MAX7219 it should look like this
+ maxSingle(1,0x1f); // + - - - - - - -
+ maxSingle(2,0x15); // - + - - - - - -,,,,,,,,
+ maxSingle(3,0x15); // - - + - - - - -
+ maxSingle(4,0x11); // - - - + - - - -
+ maxSingle(5,0xf0); // - - - - + - - -
+ maxSingle(6,0x80); // - - - - - + - -
+ maxSingle(7,0x80); // - - - - - - + -
+ maxSingle(8,0x80); // - - - - - - - +
+
+
+ //if you use more than one MAX7219, it should look like this
+
+ /*
+ maxAll(1,1); // + - - - - - - -
+ maxAll(2,3); // + + - - - - - -
+ maxAll(3,7); // + + + - - - - -
+ maxAll(4,15); // + + + + - - - -
+ maxAll(5,31); // + + + + + - - -
+ maxAll(6,63); // + + + + + + - -
+ maxAll(7,127); // + + + + + + + -
+ maxAll(8,255); // + + + + + + + +
+ */
+
+ //
+
+ //if you use more then one max7219 the second one should look like this
+
+
+ /*
+ maxOne(2,1,1); // + - - - - - - -
+ maxOne(2,2,2); // - + - - - - - -
+ maxOne(2,3,4); // - - + - - - - -
+ maxOne(2,4,8); // - - - + - - - -
+ maxOne(2,5,16); // - - - - + - - -
+ maxOne(2,6,32); // - - - - - + - -
+ maxOne(2,7,64); // - - - - - - + -
+ maxOne(2,8,128); // - - - - - - - +
+
+
+
+ //
+ wait_ms(2000);
+
+}*/
+/*
+class LEDMatrix7219{
+
+public:
+
+ LEDMatrix(PinName din, PinName clk, PinName load);
+
+ void setIntensity(float intensity);
+ void setMode
+};*/
#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MatrixSPI.cpp Mon May 26 12:29:55 2014 +0000
@@ -0,0 +1,20 @@
+#include "MatrixSPI.h"
+
+ void MatrixSPI::setup () {
+ // initiation of the max 7219
+ // SPI setup: 8 bits, mode 0
+ max72_spi.format(8, 0);
+
+ // going by the datasheet, min clk is 100ns so theoretically 10MHz should work...
+ // max72_spi.frequency(10*MHZ);
+
+ sendSingle(scanLimit, 0x07);
+ sendSingle(decodeMode, 0x00); // using an led matrix (not digits)
+ sendSingle(shutdown, 0x01); // not in shutdown mode
+ sendSingle(displayTest, 0x00); // no display test
+ for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
+ sendSingle(e,0);
+ }
+ sendSingle(intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
+ // range: 0x00 to 0x0f
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MatrixSPI.h Mon May 26 12:29:55 2014 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+
+#ifndef MATRIXSPI_H
+#define MATRIXSPI_H
+
+#define LOW 0
+#define HIGH 1
+#define MHZ 1000000
+
+class MatrixSPI
+{
+
+public:
+ const static int NOOP = 0x00;
+ const static int digit0 = 0x01;
+ const static int digit1 = 0x02;
+ const static int digit2 = 0x03;
+ const static int digit3 = 0x04;
+ const static int digit4 = 0x05;
+ const static int digit5 = 0x06;
+ const static int digit6 = 0x07;
+ const static int digit7 = 0x08;
+ const static int decodeMode = 0x09;
+ const static int intensity = 0x0a;
+ const static int scanLimit = 0x0b;
+ const static int shutdown = 0x0c;
+ const static int displayTest = 0x0f;
+
+ MatrixSPI(PinName data_input = dp2, PinName clock = dp6, PinName loadcs = dp24)
+ :max72_spi(data_input, NC, clock), load(loadcs)
+ #warning ako ne radi- NC zamijeniti sa dp1
+ { setup(); }
+
+ void setup ();
+
+ void sendSingle(int reg, int data) {
+ load = LOW; // begin
+ max72_spi.write(reg); // specify register
+ max72_spi.write(data); // put data
+ load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
+ }
+
+ void turnON(){
+ sendSingle(shutdown, 0x01); // not in shutdown mode
+ }
+
+ void turnOFF(){
+ sendSingle(shutdown, 0x00);
+ }
+
+private:
+ SPI max72_spi;
+ DigitalOut load;
+};
+
+#endif // MATRIXSPI_H
--- a/main.cpp Mon May 19 18:17:34 2014 +0000
+++ b/main.cpp Mon May 26 12:29:55 2014 +0000
@@ -1,173 +1,33 @@
#include "mbed.h"
-#include "LEDMatrix.h"
-
-//DigitalOut myled(LED1);
-AnalogIn pot(dp9);
-Serial pc(USBTX, USBRX);
-
-Ticker t;
-
-
-
-// p5: DIN, p7: CLK, p8: LOAD/CS
-SPI max72_spi(dp2, dp1, dp6);
-DigitalOut load(dp24); //Chip_Select
-
-int maxInUse = 1; //change this variable to set how many MAX7219's you'll use
-
-// define max7219 registers
-#define max7219_reg_noop 0x00
-#define max7219_reg_digit0 0x01
-#define max7219_reg_digit1 0x02
-#define max7219_reg_digit2 0x03
-#define max7219_reg_digit3 0x04
-#define max7219_reg_digit4 0x05
-#define max7219_reg_digit5 0x06
-#define max7219_reg_digit6 0x07
-#define max7219_reg_digit7 0x08
-#define max7219_reg_decodeMode 0x09
-#define max7219_reg_intensity 0x0a
-#define max7219_reg_scanLimit 0x0b
-#define max7219_reg_shutdown 0x0c
-#define max7219_reg_displayTest 0x0f
-
-#define LOW 0
-#define HIGH 1
-#define MHZ 1000000
-
-void maxSingle( int reg, int col) {
-//maxSingle is the "easy" function to use for a
-//single max7219
- load = LOW; // begin
- max72_spi.write(reg); // specify register
- max72_spi.write(col); // put data
- load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
-}
-
-void maxAll (int reg, int col) { // initialize all MAX7219's in the system
- load = LOW; // begin
- for ( int c=1; c<= maxInUse; c++) {
- max72_spi.write(reg); // specify register
- max72_spi.write(col); // put data
- }
- load = HIGH;
-}
-
-void maxOne(int maxNr, int reg, int col) {
-//maxOne is for adressing different MAX7219's,
-//while having a couple of them cascaded
- int c = 0;
- load = LOW;
-
- for ( c = maxInUse; c > maxNr; c--) {
- max72_spi.write(0); // no-op
- max72_spi.write(0); // no-op
- }
-
- max72_spi.write(reg); // specify register
- max72_spi.write(col); // put data
-
- for ( c=maxNr-1; c >= 1; c--) {
- max72_spi.write(0); // no-op
- max72_spi.write(0); // no-op
- }
- load = HIGH;
-}
-
-void setup () {
- // initiation of the max 7219
- // SPI setup: 8 bits, mode 0
- max72_spi.format(8, 0);
-
- // going by the datasheet, min clk is 100ns so theoretically 10MHz should work...
- // max72_spi.frequency(10*MHZ);
+class Par{
- maxAll(max7219_reg_scanLimit, 0x07);
- maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
- maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode
- maxAll(max7219_reg_displayTest, 0x00); // no display test
- for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
- maxAll(e,0);
- }
- maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
- // range: 0x00 to 0x0f
-}
-
-void loop () {
+};
+class Mapa{
- //if you use just one MAX7219 it should look like this
- maxSingle(1,0x1f); // + - - - - - - -
- maxSingle(2,0x15); // - + - - - - - -,,,,,,,,
- maxSingle(3,0x15); // - - + - - - - -
- maxSingle(4,0x11); // - - - + - - - -
- maxSingle(5,0xf0); // - - - - + - - -
- maxSingle(6,0x80); // - - - - - + - -
- maxSingle(7,0x80); // - - - - - - + -
- maxSingle(8,0x80); // - - - - - - - +
-
-
- //if you use more than one MAX7219, it should look like this
+};
- /*
- maxAll(1,1); // + - - - - - - -
- maxAll(2,3); // + + - - - - - -
- maxAll(3,7); // + + + - - - - -
- maxAll(4,15); // + + + + - - - -
- maxAll(5,31); // + + + + + - - -
- maxAll(6,63); // + + + + + + - -
- maxAll(7,127); // + + + + + + + -
- maxAll(8,255); // + + + + + + + +
- */
-
- //
-
- //if you use more then one max7219 the second one should look like this
-
+#include "MatrixSPI.h"
- /*
- maxOne(2,1,1); // + - - - - - - -
- maxOne(2,2,2); // - + - - - - - -
- maxOne(2,3,4); // - - + - - - - -
- maxOne(2,4,8); // - - - + - - - -
- maxOne(2,5,16); // - - - - + - - -
- maxOne(2,6,32); // - - - - - + - -
- maxOne(2,7,64); // - - - - - - + -
- maxOne(2,8,128); // - - - - - - - +
-*/
-
-
- //
- wait_ms(2000);
+MatrixSPI mspi;
-}
-/*
-class LEDMatrix7219{
-
-public:
-
- LEDMatrix(PinName din, PinName clk, PinName load);
-
- void setIntensity(float intensity);
- void setMode
-};*/
-
-void funkcija(){
+/*void funkcija(){
int temp = pot*16;
load = LOW;
max72_spi.write(max7219_reg_intensity);
max72_spi.write(temp);
load = HIGH;
-}
+}*/
+
-DigitalOut enable(dp14);
int main() {
- enable = 1;
- t.attach(&funkcija, 0.01);
+ //enable = 1;
+ mspi.setup();
+ /*t.attach(&funkcija, 0.01);
setup ();
while(1){
loop ();
- }
+ }*/
}