Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Program Documentation #2

Open
fabianhugo opened this issue Jul 5, 2023 · 3 comments
Open

Demo Program Documentation #2

fabianhugo opened this issue Jul 5, 2023 · 3 comments

Comments

@fabianhugo
Copy link

fabianhugo commented Jul 5, 2023

Links:
Legacy Mini Demo Programm: https://github.com/calliope-mini/calliope-demo
Doku für die Microbit Runtime: https://lancaster-university.github.io/microbit-docs/ubit/
Um zu Speichern, dass der Calliope bereits einmal an war: https://lancaster-university.github.io/microbit-docs/ubit/storage/
Unofficial get started documentation: https://microbit.c272.org/

RGB LEDs können mit internem Treiber verwendet werden, z.B.

    int length = 3;
    // Brightness of pixels
    int brightness = 32;
    // Create a buffer to hold pixel data of the appropriate size
    ManagedBuffer b(length*3);
    b.fill(0);
    b[0]=brightness; //turns 1st LED green
    b[1]=0;
    b[2]=0;
    b[3]=0;
    b[4]=brightness; //turns 2nd LED red
    b[5]=0;
    b[6]=0;
    b[7]=0;
    b[8]=brightness; //turns 3rd LED blue
    neopixel_send_buffer(uBit.io.RGB, b);

Ziel ist calliope mini 2 Demo Programm nachzubauen ab dem Moment wo das Hi auf dem Display scrollt.

  • Sound über int. Speaker abspielen kann mit playfreq realisiert werden.
  • Microphone funktioniert noch nicht.
    • Microphone kann getestet werden mit mems_mic_test(), wenn in deren Funktion SERIAL_STREAM_MODE_BINARY zu SERIAL_STREAM_MODE_DECIMAL geändert wird
  • Funktionen aus SpeakerTest.cpp laufen nicht, weil die einen externen Speaker verwenden (P0)

Programm Abschnitte:

  1. Test Routine (Display,RGB Leds, eCompass, Button A, Speaker)
  2. Willkommens Programm (Hi, Button Presses, Shake, LED Fade)
  3. Programmauswahl
    Wenn die Programmabschnitte 1 und 2 durchlaufen sind, wird bei Neustart immer am nächsten Programm Abschnitt gestartet. z.B: Wenn der Test durchgelaufen ist, startet immer das Willkommens Programm nach Neustart. Wenn Das Willkommensprogramm durchlaufen ist, startet immer die Programmauswahl.
@fabianhugo
Copy link
Author

fabianhugo commented Jul 11, 2023

Mit diesem Code kommen Werte aus dem Mikro.

#include "MicroBit.h"
#include "samples/Tests.h"

MicroBit uBit;
int v;


int main()
{


    uBit.audio.activateMic();
    uBit.sleep(100); // seems to be necessary
    while(1){    
        
        
        v=uBit.audio.levelSPL->getValue(); //what is SPL?
        uBit.serial.printf("%d \n",v);
        uBit.sleep(100);
    }

    
    // out_of_box_experience();
}

Fehlermeldung: RGB Pin not found:

  • Problem ist das microbit-v2-samples immer die codal auf master auscheckt.
  • in codal.json muss branch angepasst werden zu: "branch": "v0.2.50calli_proto2_5",

@fabianhugo fabianhugo changed the title Demo Program Documntation Demo Program Documentation Jul 18, 2023
@fabianhugo
Copy link
Author

fabianhugo commented Jul 19, 2023

damit kommen gute werte aus dem microphon

#include "MicroBit.h"
#include "samples/Tests.h"
#include "LevelDetector.h"
#include "LevelDetectorSPL.h"

#define MICROPHONE_MIN 52.0f
#define MICROPHONE_MAX 120.0f

MicroBit uBit;

int soundLevel() {

    LevelDetectorSPL* level = uBit.audio.levelSPL;
    if (NULL == level)
        return 0;
    const int micValue = level->getValue();
    const int scaled = max(MICROPHONE_MIN, min(micValue, MICROPHONE_MAX)) - MICROPHONE_MIN;
    return min(0xff, scaled * 0xff / (MICROPHONE_MAX - MICROPHONE_MIN));

}

int main()
{


    uBit.audio.activateMic();


    uBit.sleep(100); // seems to be necessary
    while(1){    

        uBit.serial.printf("%d \n",soundLevel());
        uBit.sleep(100);
    }

    
    // out_of_box_experience();
}

@fabianhugo
Copy link
Author

HSL color transition:

typedef struct {
    double r;       // a fraction between 0 and 1
    double g;       // a fraction between 0 and 1
    double b;       // a fraction between 0 and 1
} rgb;

typedef struct {
    double h;       // angle in degrees
    double s;       // a fraction between 0 and 1
    double v;       // a fraction between 0 and 1
} hsv;

static rgb   hsv2rgb(hsv in);

rgb hsv2rgb(hsv in)
{
    double      hh, p, q, t, ff;
    long        i;
    rgb         out;

    if(in.s <= 0.0) {       // < is bogus, just shuts up warnings
        out.r = in.v;
        out.g = in.v;
        out.b = in.v;
        return out;
    }
    hh = in.h;
    if(hh >= 360.0) hh = 0.0;
    hh /= 60.0;
    i = (long)hh;
    ff = hh - i;
    p = in.v * (1.0 - in.s);
    q = in.v * (1.0 - (in.s * ff));
    t = in.v * (1.0 - (in.s * (1.0 - ff)));

    switch(i) {
    case 0:
        out.r = in.v;
        out.g = t;
        out.b = p;
        break;
    case 1:
        out.r = q;
        out.g = in.v;
        out.b = p;
        break;
    case 2:
        out.r = p;
        out.g = in.v;
        out.b = t;
        break;

    case 3:
        out.r = p;
        out.g = q;
        out.b = in.v;
        break;
    case 4:
        out.r = t;
        out.g = p;
        out.b = in.v;
        break;
    case 5:
    default:
        out.r = in.v;
        out.g = p;
        out.b = q;
        break;
    }
    return out;     
}
void rainbow(void){
    ManagedBuffer b(3 * 3);
    hsv color;


    uBit.display.setBrightness(0);
    uBit.display.print(smiley);
    color.h=0; // angle
    color.s=1; // saturation
    color.v=0.16; //brightness
    for(int j=0; j<300; j++) { // 
        for(int i=0; i<3; i++) {
            color.h = color.h +i*30; // different color for each RGB led
            b[0+i*3]= (int)(hsv2rgb(color).g*255);
            b[1+i*3]= (int)(hsv2rgb(color).b*255);
            b[2+i*3]= (int)(hsv2rgb(color).r*255);

        }
        color.h=j; // increment angle
        uBit.sleep(10); // speed of transition
        neopixel_send_buffer(uBit.io.RGB, b);
        uBit.display.setBrightness(j);
    } 
    for(int j=0; j<31; j++) { // brightness is 0.16, slowly reduce
        color.h = 300; // start with previous color
        color.v = color.v - 0.005; // dim rgb
        for(int i=0; i<3; i++) {
            color.h = color.h + i*30; // different color for each RGB led
            b[0+i*3]= (int)(hsv2rgb(color).g*255);
            b[1+i*3]= (int)(hsv2rgb(color).b*255);
            b[2+i*3]= (int)(hsv2rgb(color).r*255);

        }
        neopixel_send_buffer(uBit.io.RGB, b);
        uBit.display.setBrightness(300-j*10); //dim display
        uBit.sleep(10);
    }
    uBit.display.clear();
    uBit.display.setBrightness(100); // restore brightness
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant