Closed htbscHKBen closed 1 year ago
Hi @htbscHKBen, thanks for the PR! Would you be able to summarise what's the difference between this file and https://github.com/lancaster-university/microbit-v2-samples/blob/master/source/samples/OOB.cpp ?
Comparing the file added here with source/samples/OOB.cpp
and they are identical, so I'll close this as an accidental PR.
@htbscHKBen if I'm mistaken please reopen the PR and we can look into it.
/*
include "MicroBit.h"
include "Tests.h"
include
include "Synthesizer.h"
define OOB_SHAKE_OVERSAMPLING 5
define OOB_SHAKE_OVERSAMPLING_THRESHOLD 4
define OOB_SHAKE_THRESHOLD 1200
enum modes { WAKE = 0, INTRO, BUTTON_A, BUTTON_B, LOGO_BUTTON, TURN, DOTCHASER, CLAP, NEXT, SECRET };
int mode; int accelX, accelY; int targetX, targetY; bool flag = false; MicroBitImage currentFrame; bool mute = false;
int basenote = 52;
//shake game int shake_detected = 0; int shakeCount; int xMin; int xMax; int yMin; int yMax; int prevX; int prevY;
// Images and animations -----------------
const MicroBitImage dot("0,255,0,255,0\n255,255,255,255,255\n255,255,255,255,255\n0,255,255,255,0\n0,0,255,0,0\n");
const char *shake[] = { "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,0,0,0,0\n0,0,0,0,0\n", "0,0,0,0,0\n0,255,0,255,0\n0,0,255,0,0\n0,255,0,255,0\n0,0,0,0,0\n", "0,0,255,0,0\n0,255,0,255,0\n255,0,255,0,255\n0,255,0,255,0\n0,0,255,0,0\n", "255,0,255,0,255\n0,255,0,255,0\n255,0,255,0,255\n0,255,0,255,0\n255,0,255,0,255\n", "255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n"
};
const char *wakeAnim[] = { "0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,0,0,0,0\n0,0,0,0,0\n", "0,0,0,0,0\n0,255,255,255,0\n0,255,255,255,0\n0,255,255,255,0\n0,0,0,0,0\n", "255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n" };
const char *explosionTime[] = { "255,255,255,255,255\n255,0,0,0,255\n255,0,0,0,255\n255,0,0,0,255\n255,255,255,255,255\n", "255,255,255,255,255\n255,255,255,255,255\n255,255,0,255,255\n255,255,255,255,255\n255,255,255,255,255\n", "255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n", "0,0,0,0,0\n0,255,255,255,0\n0,255,255,255,0\n0,255,255,255,0\n0,0,0,0,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,0,0,0,0\n0,0,0,0,0\n", "0,0,0,0,0\n0,255,0,255,0\n0,0,0,0,0\n0,255,0,255,0\n0,0,0,0,0\n", "255,0,0,0,255\n0,0,255,0,0\n0,255,255,255,0\n0,0,255,0,0\n255,0,0,0,255\n", "0,0,255,0,0\n0,255,0,255,0\n255,0,0,0,255\n0,255,0,255,0\n0,0,255,0,0\n", "255,0,0,0,255\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n255,0,0,0,255\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n"
};
const char *twistyTime[] = { "0,0,0,0,0\n0,0,0,0,0\n255,0,0,0,255\n0,0,0,0,0\n0,0,0,0,0\n", "0,0,0,0,0\n255,0,0,0,255\n255,255,0,255,255\n255,0,0,0,255\n0,0,0,0,0\n", "255,0,0,0,255\n255,255,0,255,255\n255,255,255,255,255\n255,255,0,255,255\n255,0,0,0,255\n", "0,0,0,255,255\n255,0,0,255,255\n255,255,255,255,255\n255,255,0,0,255\n255,255,0,0,0\n", "0,255,255,255,255\n0,0,255,255,255\n255,0,255,0,255\n255,255,255,0,0\n255,255,255,255,0\n", "255,255,255,255,255\n0,0,255,255,255\n0,0,255,0,0\n255,255,255,0,0\n255,255,255,255,255\n", "255,255,255,255,255\n0,255,255,255,0\n0,0,255,0,0\n0,255,255,255,0\n255,255,255,255,255\n", "0,255,255,255,0\n0,0,255,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,255,255,255,0\n", "0,0,255,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n" };
const char *heart[] = { "0,255,0,255,0\n255,255,255,255,255\n255,255,255,255,255\n0,255,255,255,0\n0,0,255,0,0\n" };
// Arrow images and animations. const MicroBitImage arrowUpTime("0,0,255,0,0\n0,255,255,255,0\n255,0,255,0,255\n0,0,255,0,0\n0,0,255,0,0\n");
const char *arrowDisintegrationTime[] = { "0,0,0,0,0\n0,0,255,0,0\n0,0,255,0,0\n255,0,255,0,255\n0,255,255,255,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,0,255,0,0\n255,0,255,0,255\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n0,0,255,0,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,255,0,0\n", "0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n" };
// Bottom arrow from left to right const char *bottomArrow[] = { "0,0,255,0,0\n0,255,0,0,0\n255,255,255,255,255\n0,255,0,0,0\n0,0,255,0,0\n", "0,0,0,0,255\n255,0,0,255,0\n255,0,255,0,0\n255,255,0,0,0\n255,255,255,255,0\n", "0,0,255,0,0\n0,0,255,0,0\n255,0,255,0,255\n0,255,255,255,0\n0,0,255,0,0\n", "255,0,0,0,0\n0,255,0,0,255\n0,0,255,0,255\n0,0,0,255,255\n0,255,255,255,255\n", "0,0,255,0,0\n0,0,0,255,0\n255,255,255,255,255\n0,0,0,255,0\n0,0,255,0,0\n" };
const char *topArrow[] = { "0,0,255,0,0\n0,255,0,0,0\n255,255,255,255,255\n0,255,0,0,0\n0,0,255,0,0\n", "255,255,255,255,0\n255,255,0,0,0\n255,0,255,0,0\n255,0,0,255,0\n0,0,0,0,255\n", "0,0,255,0,0\n0,255,255,255,0\n255,0,255,0,255\n0,0,255,0,0\n0,0,255,0,0\n", "0,255,255,255,255\n0,0,0,255,255\n0,0,255,0,255\n0,255,0,0,255\n255,0,0,0,0\n", "0,0,255,0,0\n0,0,0,255,0\n255,255,255,255,255\n0,0,0,255,0\n0,0,255,0,0\n" };
int target_freq; int current_freq; int playback_sleep = 5; int slide = 1; int chatter = false; int chatter_toggle = false;
// --------------------------- void playfreq(int freq) { if (mute || freq == 0) { uBit.io.speaker.setAnalogValue(0); uBit.io.P0.setAnalogValue(0); return; } uBit.io.speaker.setHighDrive(true); uBit.io.speaker.setAnalogValue(512); uBit.io.P0.setHighDrive(true); uBit.io.P0.setAnalogValue(512); int period = 1000000.0/(float)freq;
uBit.io.speaker.setAnalogPeriodUs(period); uBit.io.P0.setAnalogPeriodUs(period); return; }
void play_note(uint8_t note) { if(note == 0) { target_freq = 0; return; }
}
void playback_ticker() { // Thread forever while(1) {
}
// Wake up the device void wake() { uBit.display.setBrightness(0); // Turn on all pixels. for(int y=0; y<5; y++) { for(int x=0; x<5; x++) { uBit.display.image.setPixelValue(x, y, 255); } }
}
void intro() { // Introduce the micro:bit. uBit.display.image.clear(); chatter = true; uBit.display.scroll("HELLO", 150); chatter = false;
}
int button_a_pressed = false; void OOB_onButtonA(MicroBitEvent) { button_a_pressed = true; }
void pressButtonA() { // Give instruction // uBit.display.print("A"); uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, OOB_onButtonA);
}
int button_b_pressed = false; void OOB_onButtonB(MicroBitEvent) { button_b_pressed = true; }
void pressButtonB() { // Give instruction
uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, OOB_onButtonB);
}
int button_logo_pressed = false; void OOB_onButtonLogo(MicroBitEvent) { button_logo_pressed = true; }
void pressLogoButton() { // Give instruction
uBit.messageBus.listen(MICROBIT_ID_LOGO, MICROBIT_BUTTON_EVT_CLICK, OOB_onButtonLogo);
}
void updateAccelPosition() { accelX = 0; accelY = 0;
}
void turn() { int timeout = 0; int samples_high; int x, y, z, magnitude;
}
void insertNewTarget() { targetX = uBit.random(4); targetY = uBit.random(4); if(targetX == 0 && targetY == 0) targetY++; else if(targetX == 0 && targetY == 4) targetY--; else if(targetX == 4 && targetY == 0) targetY++; else if(targetX == 4 && targetY == 4) targetY--; }
void dotChaser() { uBit.display.scroll("TILT", 200);
}
define SNAKE_EMPTY 0
define SNAKE_UP 1
define SNAKE_LEFT 2
define SNAKE_RIGHT 3
define SNAKE_DOWN 4
define SNAKE_FRAME_DELAY 350
struct Point { int x; int y; };
Point head; // Location of the head of our snake. Point tail; // Location of the tail of our snake. Point food; // Location of food. MicroBitImage map(5,5);
void place_food() { int r = uBit.random(24); int x = 0; int y = 0;
}
void snake() {
Point newHead; // Calculated placement of new head position based on user input.
int hdirection; // Head's direction of travel int tdirection; // Tail's direction of travel int snakeLength; // number of segments in the snake. int growing; // boolean state indicating if we've just eaten some food.
}
void OOB_onButtonAExtra() { uBit.display.stopAnimation(); for(int i=0; i<10; i++) { currentFrame = MicroBitImage(explosionTime[i]); uBit.display.print(currentFrame,0,0,0,100); play_note(basenote + (i * 5)) ; } currentFrame = MicroBitImage(heart[0]);
play_note(0); uBit.display.image.clear(); uBit.display.print(currentFrame,0,0,0,400); mode++; }
void OOB_onButtonBExtra() { uBit.display.stopAnimation(); for(int i=0; i<10; i++) { currentFrame = MicroBitImage(twistyTime[i]); uBit.display.print(currentFrame,0,0,0,100); play_note(basenote + (95) - (i 5)) ; } play_note(0); currentFrame = MicroBitImage(heart[0]);
uBit.display.image.clear(); uBit.display.print(currentFrame,0,0,0,400); mode++; }
void next() { if(flag == false){ flag = true; for(int i = 0; i < 5; i++) { play_note(basenote + i * 5); uBit.sleep(100); } play_note(0); uBit.display.scroll("WOW!", 200); }
}
void make_noise() { uBit.display.scroll("MAKE NOISE!", 200); level_meter(); mode++; }
void clap() { uBit.display.scroll("CLAP!", 200); mems_clap_test(1); mode++; }
void onFacePalm(MicroBitEvent e) { uBit.serial.printf("face palm \r\n"); mute = !mute; }
void out_of_box_experience() {
target_freq = 0; current_freq = 0;
mode = LOGO_BUTTON;
}