Understanding C++, some help please

Im trying to figure some stuff out to learn programming for the Pokitto. However i dont know sh*t about C++ :blush:

I have been fooling around in this code :

#include "Pokitto.h"

Pokitto::Core mygame;
Pokitto::Core pokitto;

int main () {
    while (mygame.isRunning()) {
        if (mygame.update()) {            
                // change the name as long as button is pressed
            //playTone (1, 2, 2, 5, 5);             


Could someone tell why buttons can only be used if i add Pokitto::Core pokitto; ? Is this not something the #include pokitto.h does already ?

And what should i use for just making it beep? Playtone is not defined according to the mbed compiler. Or do i need another reference for that ?

You mean mygame.buttons.aBtn() does not work?

Pokitto::Core pokitto and Pokitto::Core mygame are the exact same thing. They point to the same object in memory.

A ok, so i removed the pokitto::core mygame and got errors all over.
But this helped, i now understand that the name after pokitto::core is linked. So every command should start with that name.

But what about the sound? Is there something that fits into 1 line to generate a tone or a beep ?

I need to get back to you on the sound, my attention is split among several things at the moment.

You can also do this with ll the different “subsystems”:

#include "Pokitto.h"

Pokitto::Core mygame;
Pokitto::Buttons bttn;

While (mygame.isRunning()) { ... and so on
if (bttn.aBtn()) { .... and so on

Pokitto::Buttons bttn will be pointing inside mygame object structure - in fact it will be the same thing as mygame.buttons! This is a trick you can use to shorten the amount of code you need to write and it does not cost you any extra memory!


For a beep, I used:

       setOSC(&osc1,1,WSAW,0,0,0,46,255,0,0,0,0,0,0,0,0,0); // 46 NOTE_A4 440Hz

But, you also need to have these in your My_settings.h

      #define PROJ_ENABLE_SOUND 1
      #define PROJ_ENABLE_SYNTH 1

and this in your main.cpp

      #include "Synth.h"
1 Like

I tried this, but i dont get a beep. No errors during build. Should be easily to hear ?

I tried exactly same code and settings but cannot get sound. I am confused about that.

Tried with a new project, or adding to an existing project? I think you need to ‘rebuild’ if you change anything in My_settings.h?

I do a rebuild, then if it is succesfull i compile to bin.

I suspect Sound is still on the ToDo list of @jonne :slight_smile:

or we need to activate the sound first?

in asterocks playsoundfx(1,0); was used.

Well, sound works but I need to make better examples for how to program it.

1 Like

Well, those are the commands I used for sound in this game, and I can hear it on my Pokitto?

Honestly, it should not be this complicated to have a simple working ‘Tone’ command though! :confused:

aha it does work! but for some reason it is very soft. I could only hear it with a headset and on the max volume.
Using the the speaker of pokitto itself i think i hear something, but im not sure.

Making sure the speaker does work i tried the test animation, and that works good.

edit: could it be the sound volume has to be set in software as well ?

There are ‘hotkeys’ you can use while in-game to adjust the volume (from Pokitto Quick Reference poster):

…a little disappointing if I am the only one who was hearing the sound in that game! :disappointed:

I will make the sound more user friendly to use

I was aware of this, but even at max volume i cant here it clearily. Perhaps a different tone ?

So even running text.bin from the game page I linked to above you hardly hear the sound at all? Because it works fine on my Pokitto… if that is the case then I would begin to suspect a hardware fault?

No, lets be clear here. The speaker from pokitto is working.
If i use the animation test i can hear the feelgood sound.
However this is not very loud, but perhaps that is just the soundlevel/volume the pokitto can produce.

If i use the text.bin i cannot tell if pokitto is making a sound or not.
Using a headset and setting the volume to max i can here te beep in the game.

So sound is working, but i am expecting it to be a little louder.

And as a extra i have to set the max soundlevel everytime i boot. Since pokitto doesnt make a hearable sound on the lower levels, i have to set this to the max 255. Then after starting the game i set it to higher volume.

OK, a better test might be to run the synth test:

If you set the headphone limit at start-up to anything above 32, then you should get Volume and HWVolume at 255 and hear a nice clear loud sound?

1 Like

Just tried the synthesizer functions from the Tutorial and it works good. Nice clear sound.

Do any of you hear the sounds in the Text game clearly ?