p kj
/
LPC824-DotMatrix
Microduino
Fork of LED_DZ by
Diff: main.cpp
- Revision:
- 1:14b7c3a3ec60
- Parent:
- 0:5ca227682ee7
- Child:
- 2:487a727d6181
--- a/main.cpp Tue May 31 15:32:03 2016 +0000 +++ b/main.cpp Wed Jun 01 13:38:30 2016 +0000 @@ -64,7 +64,7 @@ 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xDD, 0x00, 0x00, }; -DigitalOut myled(LED1); +DigitalOut myled(D13); #define delay wait_ms void randomSeed(unsigned long seed) { @@ -91,30 +91,35 @@ return random(diff) + howsmall; } +Serial pc(P0_4,P0_0); +#if 0 int main() { int i; char buf[32]; + myled = 0; + pc.baud(115200); g_Timer.start(); -#if 0 +#if 1 //getDeviceAddr for (int a = 0; a < display.getMatrixNum(); a++) { - Serial.print(display.getDeviceAddr(a)); - Serial.print(" "); + pc.printf("device add = %d", display.getDeviceAddr(a)); + pc.printf(" "); } - Serial.println(""); + pc.printf("\r\n"); #endif - + myled = !myled; display.clearDisplay(); //setLedColor for (int y = 0; y < display.getHeight() * 8; y++) { for (int x = 0; x < display.getWidth() * 8; x++) { - randomSeed(45); + randomSeed(x); display.setLedColor(x, y, random(0, 255), random(0, 255), random(0, 255)); //x, y, r, g, b - delay(5); + delay(1000); } } delay(1000); + myled = !myled; //setLed display.clearDisplay(); @@ -126,6 +131,7 @@ } } delay(1000); + myled = !myled; //setLed display.clearDisplay(); @@ -137,16 +143,19 @@ } } delay(1000); + myled = !myled; display.clearDisplay(); display.setColor(0, 255, 0); display.drawBMP(0, 0, 8, 8, logoA); //x,y,w,h,data delay(2000); + myled = !myled; display.clearDisplay(); //Windows Bitmap (BMP) file,24bit display.drawBMP(0, 0, logoB); //x,y,data delay(2000); + myled = !myled; //clearColor display.clearColor(); @@ -156,8 +165,9 @@ //writeString V display.writeString("Microduino", MODE_V, 20, 0); //string, MODE, time ,x display.clearDisplay(); + myled = !myled; while(1) { - display.setColor(255, 255, 0); + display.setColor(random(0, 255), random(0, 255), random(0, 255)); display.drawBox(0, 0, 8, 8); //x,y,w,h delay(2000); @@ -236,5 +246,185 @@ display.setColor(255, 255, 255); display.clearDisplay(); display.writeString(buffer_data, MODE_H, 50, 1); + myled = !myled; + } +} +#elif 0 +int main() +{ + int i; + char buf[32]; + myled = 0; + pc.baud(115200); + g_Timer.start(); + pc.printf("rand max = %d\r\n", RAND_MAX); +#if 1 + //getDeviceAddr + for (int a = 0; a < display.getMatrixNum(); a++) { + pc.printf("device add = %d", display.getDeviceAddr(a)); + pc.printf(" "); + } + pc.printf("\r\n"); + //wait(5.0); + pc.printf("Let us go into while\r\n"); +#endif + while (1) { + myled = 1; + //wait(2.0); + //pc.printf("clearDisplay....\r\n"); + display.clearDisplay(); + int16_t height = display.getHeight(); + int16_t width = display.getWidth(); + //pc.printf("height = %d, width = %d\r\n", height, width); + for (int y = 0; y < display.getHeight() * 8; y++) { + for (int x = 0; x < display.getWidth() * 8; x++) { + randomSeed(23); + //display.setLedColor(x, y, random(0, 255), random(0, 255), random(0, 255)); //x, y, r, g, b + display.setLedColor(x, y, 156, 200, 56); //x, y, r, g, b + wait_ms(5); + } + } + myled = 0; + wait(1); + } +} +#elif 0 +I2C i2c(P0_11, P0_10); +void main() +{ + pc.baud(115200); + pc.printf("Hello Microduino!\r\n"); + wait(3.5); + i2c.frequency(400000); + //i2c.start(); + uint8_t address = 64; + char cmd = 0x60; + int ret = i2c.write(address<<1, &cmd, 1, false); + //int ret = i2c.write(0x60); + pc.printf("clear led ret = %d\r\n", ret); + //i2c.stop(); + + uint8_t _value_r = random(0, 255); + uint8_t _value_g = random(0, 255); + uint8_t _value_b = random(0, 255); + uint8_t temp[4]; + //temp[0] = 0x80 | (_row << 3) | _col; + temp[1] = _value_b / 8; + temp[2] = 0x20 | _value_g / 8; + temp[3] = 0x40 | _value_r / 8; + randomSeed(23); + while (1) { + i2c.write(address<<1, &cmd, 1, false); + wait_ms(900); + myled = !myled; + for (int y = 0; y < display.getHeight() * 8; y++) { + for (int x = 0; x < display.getWidth() * 8; x++) { + //randomSeed(23); + //display.setLedColor(x, y, random(0, 255), random(0, 255), random(0, 255)); //x, y, r, g, b + //display.setLedColor(x, y, 156, 200, 56); //x, y, r, g, b + _value_r = random(0, 255); + _value_g = random(0, 255); + _value_b = random(0, 255); + temp[0] = 0x80 | (x << 3) | y; + temp[1] = _value_b / 8; + temp[2] = 0x20 | _value_g / 8; + temp[3] = 0x40 | _value_r / 8; + i2c.write(address<<1, (char*)temp, 4, false); + wait_ms(5); + } + } + wait(1.9); } } +#elif 0 +void main() +{ + randomSeed(gAnalogIn.read_u16()); + while (1) { + display.setColor(random(0, 255), random(0, 255), random(0, 255)); + display.drawBox(0, 0, 8, 8); //x,y,w,h + delay(2000); + display.clearDisplay(); + delay(599); + //randomSeed(gAnalogIn.read_u16()); + } +} +#else +uint8_t donghua[128] = { + 0,0, 1,0, 2,0, 3,0, 4,0, 5,0, 6,0, 7,0, + 7,1, 7,2, 7,3, 7,4, 7,5, 7,6, 7,7, + 6,7, 5,7, 4,7, 3,7, 2,7, 1,7, 0,7, + 0,6, 0,5, 0,4, 0,3, 0,2, 0,1, + 1,1, 2,1, 3,1, 4,1, 5,1, 6,1, +}; +void main() +{ + uint8_t r,g,b; + randomSeed(gAnalogIn.read_u16()); + display.clearDisplay(); + int8_t x = 0; + int8_t y = 0; + int8_t xMax = 7; + int8_t yMax = 7; + int8_t xMin = 0; + int8_t yMin = 0; + uint8_t state = 0; + r = random(0, 255); + g = random(0, 255); + b = random(0, 255); + while (true) { + display.setLedColor(x, y, r, g, b); //x, y, r, g, b + delay(50); + if (x == 3 && y == 4) { + x = 0; + y = 0; + xMax = 7; + yMax = 7; + xMin = 0; + yMin = 0; + display.clearDisplay(); + delay(500); + state = 0; + r = random(0, 255); + g = random(0, 255); + b = random(0, 255); + display.setLedColor(0, 0, r, g, b); //x, y, r, g, b + //continue; + } + + if (state == 0) { + x++; + if (x > xMax) { + state = 1; + x = xMax; + y++; + } + } else if (state == 1) { + y++; + if (y > yMax) { + state = 2; + y = yMax; + x--; + } + } else if (state == 2) { + x--; + if (x < xMin) { + state = 3; + x = xMin; + y--; + } + } else if (state == 3) { + y--; + if (y == yMin) { + state = 0; + y = yMin+1; + x++; + xMax--; + yMax--; + xMin++; + yMin++; + } + } + } +} +#endif \ No newline at end of file