Skip to content

Instantly share code, notes, and snippets.

@Pharap
Created May 5, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pharap/79dd9d27cffb3147d190211e462701fe to your computer and use it in GitHub Desktop.
Save Pharap/79dd9d27cffb3147d190211e462701fe to your computer and use it in GitHub Desktop.
Problem demo
#include <Pokitto.h>
#include <cstdint>
#include <SDFileSystem.h>
// Uncomment to cause problems
SDFileSystem sd
(
/*MOSI*/P0_9,
/*MISO*/P0_8,
/*SCK*/P0_6,
/*CS*/P0_7,
/*Mountpoint*/"sd",
NC,
SDFileSystem::SWITCH_NONE,
25000000
);
struct HighScoreEntry
{
char name[3];
unsigned int highScore;
};
// This is an array that holds your highscore entries
constexpr const std::size_t HighscoreCount = 5;
HighScoreEntry highScoreTable[HighscoreCount];
// It's better to have this as a global constant so it's easy to change
char highScoreFileName[] = "/sd/scores.txt";
int selected = 0;
void printScore(const HighScoreEntry & entry)
{
for (int i = 0; i < 3; i++)
{
Pokitto::Display::print(entry.name[i]);
Pokitto::Display::print(' ');
}
Pokitto::Display::println(entry.highScore);
}
int saveSuccess = 0;
int loadSuccess = 0;
int main (void)
{
Pokitto::Core::begin();
std::memset(highScoreTable, 0, sizeof(highScoreTable));
for (int i = 0; i < 5; ++i)
{
for (int k = 0; k < 3; ++k)
highScoreTable[i].name[k] = ('A' + i);
highScoreTable[i].highScore = 5 - i;
}
while (Pokitto::Core::isRunning())
{
if (Pokitto::Core::update())
{
Pokitto::Display::setColor(1);
Pokitto::Display::println("Hello World!");
Pokitto::Display::print(sizeof(highScoreTable));
Pokitto::Display::print(' ');
Pokitto::Display::print(sizeof(HighScoreEntry));
Pokitto::Display::print(' ');
Pokitto::Display::print(sizeof(highScoreTable) / sizeof(HighScoreEntry));
Pokitto::Display::println();
Pokitto::Display::println(loadSuccess);
Pokitto::Display::println(saveSuccess);
/*if (Pokitto::Core::buttons.pressed(BTN_A))
{
saveSuccess = saveAllHighScores(highScoreFileName, highScoreTable);
}
if (Pokitto::Core::buttons.pressed(BTN_B))
{
loadSuccess = loadAllHighScores(highScoreFileName, highScoreTable);
}*/
Pokitto::Display::setColor(1);
for (int i = 0; i < 5; ++i)
printScore(highScoreTable[i]);
}
}
return 0;
}
/**************************************************************************/
/*!
@file My_settings.h
@author XX
@section HOW TO USE My_settings
My_settings can be used to set project settings inside the mbed online IDE
*/
/**************************************************************************/
#ifndef MY_SETTINGS_H
#define MY_SETTINGS_H
#define PROJ_HIRES 0 //1 = high resolution (220x176) , 0 = low resolution fast mode (110x88)
#define PROJ_ENABLE_SOUND 0 // 0 = all sound functions disabled
#define NOPETITFATFS 1
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment