Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from ken551/fixDisplayMatrixCode
Browse files Browse the repository at this point in the history
edit: updated LED matrix related codes and adjusted indentation
  • Loading branch information
kd8bxp authored Jul 18, 2020
2 parents 2791fd7 + 95ed269 commit 4357c34
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 169 deletions.
60 changes: 30 additions & 30 deletions examples/Library_LED_Matrix_Demo/Library_LED_Matrix_Demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,101 @@
#include <Maqueen.h>
Maqueen bot;

Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;



void setup() {
Serial.begin(9600);
bot.begin();
microbit.begin();
microbit.matrix.begin();
}

void loop(){

// The Images below are from the Adafruit microbit library.
// Fill screen
microbit.fillScreen(LED_ON);
microbit.matrix.fillScreen(LED_ON);
delay(1000);

// draw a heart
microbit.show(microbit.HEART);
microbit.matrix.show(microbit.matrix.HEART);
delay(1000);
//empty heart
microbit.show(microbit.EMPTYHEART);
microbit.matrix.show(microbit.matrix.EMPTYHEART);
delay(1000);
// draw a no cross
microbit.show(microbit.NO);
microbit.matrix.show(microbit.matrix.NO);
delay(1000);

// draw a yes check
microbit.show(microbit.YES);
microbit.matrix.show(microbit.matrix.YES);
delay(1000);


microbit.clear();
microbit.matrix.clear();

//These are included in the Adafruit Microbit library.
// Draw a line 'by hand'
microbit.drawPixel(0, 0, LED_ON);
microbit.drawPixel(1, 1, LED_ON);
microbit.drawPixel(2, 2, LED_ON);
microbit.drawPixel(3, 3, LED_ON);
microbit.drawPixel(4, 4, LED_ON);
microbit.matrix.drawPixel(0, 0, LED_ON);
microbit.matrix.drawPixel(1, 1, LED_ON);
microbit.matrix.drawPixel(2, 2, LED_ON);
microbit.matrix.drawPixel(3, 3, LED_ON);
microbit.matrix.drawPixel(4, 4, LED_ON);
// draw the 'opposite' line with drawline (easier!)
microbit.drawLine(0, 4, 4, 0, LED_ON);
microbit.matrix.drawLine(0, 4, 4, 0, LED_ON);

delay(1000);

// erase screen, draw a square
microbit.clear();
microbit.drawRect(0,0, 5, 5, LED_ON); // top left corner @ (0,0), 5 by 5 pixels size
microbit.matrix.clear();
microbit.matrix.drawRect(0,0, 5, 5, LED_ON); // top left corner @ (0,0), 5 by 5 pixels size

delay(1000);

// erase screen, draw a circle
microbit.clear();
microbit.drawCircle(2,2, 2, LED_ON); // center on 2, 2, radius 2
microbit.matrix.clear();
microbit.matrix.drawCircle(2,2, 2, LED_ON); // center on 2, 2, radius 2

delay(1000);

// erase screen, draw a filled triangle
microbit.clear();
microbit.fillTriangle(0,4, 2,0, 4,4, LED_ON);
microbit.matrix.clear();
microbit.matrix.fillTriangle(0,4, 2,0, 4,4, LED_ON);

delay(1000);

//These Images are included in the Maqueen Library
//some are based off images on makecode.microbit.org
// draw a custom made bitmap face
microbit.show(smile_bmp);
microbit.matrix.show(smile_bmp);
delay(1000);

microbit.show(sad);
microbit.matrix.show(sad);
delay(1000);

microbit.show(confused);
microbit.matrix.show(confused);
delay(1000);

microbit.show(small_heart);
microbit.matrix.show(small_heart);
delay(1000);

microbit.show(up_arrow);
microbit.matrix.show(up_arrow);
delay(1000);

microbit.show(down_arrow);
microbit.matrix.show(down_arrow);
delay(1000);

microbit.show(left_arrow);
microbit.matrix.show(left_arrow);
delay(1000);

microbit.show(right_arrow);
microbit.matrix.show(right_arrow);
delay(1000);

microbit.show(ghost);
microbit.matrix.show(ghost);
delay(1000);

microbit.show(skull);
microbit.matrix.show(skull);
delay(1000);

}
10 changes: 5 additions & 5 deletions examples/library_example1_motor/library_example1_motor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ Maqueen bot;

//NewPing.h and Adafruit_Microbit.h are inlcuded the library header
//but still need to be invoked here.
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;

void setup() {
bot.begin();
microbit.begin();
microbit.matrix.begin();

while (bot.readA()) { //wait for BTNA to be pushed
microbit.print("A");
microbit.matrix.print("A");
}

microbit.clear();
microbit.show(smile_bmp);
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);

//Spin the motor to the right
bot.motorRun(M1, CW, 50); //Motor Number, direction, speed (PWM)
Expand Down
32 changes: 16 additions & 16 deletions examples/library_example2_avoid/library_example2_avoid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ Maqueen bot;
//NewPing.h and Adafruit_Microbit.h are inlcuded the library header
//but still need to be invoked here.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;


void setup() {
Serial.begin(9600);
bot.begin();
microbit.begin();
while (bot.readA()) { //wait for BTNA to be pushed
microbit.print("A");
}
microbit.clear();
microbit.show(smile_bmp);
}
microbit.matrix.begin();
while (bot.readA()) { //wait for BTNA to be pushed
microbit.matrix.print("A");
}
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);
}

void loop() {
bot.setSpeed(80); //percentage from 1 to 100
while (sonar.ping_in() >= 5) {
bot.forward();
}
bot.stop();
bot.setSpeed(60);
bot.spinLeft();
delay(100);
bot.stop();
while (sonar.ping_in() >= 5) {
bot.forward();
}
bot.stop();
bot.setSpeed(60);
bot.spinLeft();
delay(100);
bot.stop();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ Maqueen bot;

//NewPing.h and Adafruit_Microbit.h are inlcuded the library header
//but still need to be invoked here.
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;

void setup() {
Serial.begin(9600);
bot.begin(); //must include the begin (otherwise things don't work)
microbit.begin();
bot.begin(); //must include the begin (otherwise things don't work)
microbit.matrix.begin();

while (bot.readA()) { //wait for BTNA to be pushed
microbit.print("A");
}
while (bot.readA()) { //wait for BTNA to be pushed
microbit.matrix.print("A");
}

microbit.clear();
microbit.show(smile_bmp);
}
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);
}

void loop() {
digitalWrite(LED1,HIGH); //LED1 is defined in the library (left led)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ Maqueen bot;
//NewPing.h and Adafruit_Microbit.h are inlcuded the library header
//but still need to be invoked here.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;

void setup() {
Serial.begin(9600);
bot.begin();
microbit.begin();
while (bot.readA()) { //wait for BTNA to be pushed
microbit.print("A");
}
microbit.clear();
microbit.show(smile_bmp);
microbit.matrix.begin();
while (bot.readA()) { //wait for BTNA to be pushed
microbit.matrix.print("A");
}
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);

}

void loop() {
int us = sonar.ping_in();
microbit.print(us);
microbit.matrix.print(us);
Serial.println(us);
delay(1000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void setup() {
microbit.BTLESerial.setLocalName("microbit");

// Start LED matrix driver after radio (required)
microbit.begin();
microbit.clear();
microbit.show(smile_bmp);
microbit.matrix.begin();
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);
}

/**************************************************************************/
Expand Down Expand Up @@ -81,4 +81,3 @@ switch (buttnum) {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ https://kd8bxp.blogspot.com/
#include "NRF51_Radio_library.h" //https://github.com/tipih/NRF51_Radio_library

Maqueen bot;
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;
NRF51_Radio MicrobitRadio = NRF51_Radio();

static long currentMillis;
Expand All @@ -42,19 +42,19 @@ void setup() {
Serial.begin(115200);
bot.begin();
Serial.println("Gamepad Control demo ready!");
microbit.begin();
microbit.matrix.begin();
MicrobitRadio.enable();
MicrobitRadio.setGroup(10);
MicrobitRadio.setFrequencyBand(50);
Serial.println("Radio running");
microbit.clear();
microbit.show(smile_bmp);
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);
}

void loop() {

//Check if there is any data in the buffer
FrameBuffer* myData = MicrobitRadio.recv();
FrameBuffer* myData = MicrobitRadio.recv();
if (myData != NULL) {
Serial.print(myData->length);
Serial.print(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,49 @@ Maqueen bot;
//NewPing.h and Adafruit_Microbit.h are inlcuded the library header
//but still need to be invoked here.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Adafruit_Microbit_Matrix microbit;
Adafruit_Microbit microbit;

int byteValue;
int speed = 50; //50% of full speed

void setup() {
Serial.begin(9600);
Serial.begin(9600);
bot.begin();
microbit.begin();
microbit.clear();
microbit.show(smile_bmp);
microbit.matrix.begin();
microbit.matrix.clear();
microbit.matrix.show(smile_bmp);

}

void loop() {
byteValue = bot.readIR();

switch (byteValue) {
case 0:
bot.stop();
break;
case UP:
bot.setSpeed(speed);
bot.forward();
break;
case DOWN:
bot.setSpeed(speed);
bot.backward();
break;
case LEFT:
bot.setSpeed(speed);
bot.spinLeft();
break;
case RIGHT:
bot.setSpeed(speed);
bot.spinRight();
break;
case SETUP:
bot.stop();
break;
default:
bot.stop();
break;
switch (byteValue) {
case 0:
bot.stop();
break;
case UP:
bot.setSpeed(speed);
bot.forward();
break;
case DOWN:
bot.setSpeed(speed);
bot.backward();
break;
case LEFT:
bot.setSpeed(speed);
bot.spinLeft();
break;
case RIGHT:
bot.setSpeed(speed);
bot.spinRight();
break;
case SETUP:
bot.stop();
break;
default:
bot.stop();
break;
}
byteValue = 0;
}
byteValue = 0;
}


Loading

0 comments on commit 4357c34

Please sign in to comment.