Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
helloworld.hpp@2:e3ef9f476913, 2017-01-06 (annotated)
- Committer:
- lmayencou
- Date:
- Fri Jan 06 22:29:05 2017 +0000
- Revision:
- 2:e3ef9f476913
- Parent:
- 1:c53e766082b4
add printf support
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lmayencou | 0:649b2fe69f16 | 1 | /* |
| lmayencou | 0:649b2fe69f16 | 2 | Hello, World! example |
| lmayencou | 0:649b2fe69f16 | 3 | June 11, 2015 |
| lmayencou | 0:649b2fe69f16 | 4 | Copyright (C) 2015 David Martinez |
| lmayencou | 0:649b2fe69f16 | 5 | All rights reserved. |
| lmayencou | 0:649b2fe69f16 | 6 | This code is the most basic barebones code for writing a program for Arduboy. |
| lmayencou | 0:649b2fe69f16 | 7 | |
| lmayencou | 0:649b2fe69f16 | 8 | This library is free software; you can redistribute it and/or |
| lmayencou | 0:649b2fe69f16 | 9 | modify it under the terms of the GNU Lesser General Public |
| lmayencou | 0:649b2fe69f16 | 10 | License as published by the Free Software Foundation; either |
| lmayencou | 0:649b2fe69f16 | 11 | version 2.1 of the License, or (at your option) any later version. |
| lmayencou | 0:649b2fe69f16 | 12 | */ |
| lmayencou | 0:649b2fe69f16 | 13 | |
| lmayencou | 1:c53e766082b4 | 14 | #include "mbedboy.hpp" |
| lmayencou | 0:649b2fe69f16 | 15 | |
| lmayencou | 0:649b2fe69f16 | 16 | // make an instance of arduboy used for many functions |
| lmayencou | 1:c53e766082b4 | 17 | |
| lmayencou | 1:c53e766082b4 | 18 | DigitalOut led2(LED2); |
| lmayencou | 1:c53e766082b4 | 19 | |
| lmayencou | 1:c53e766082b4 | 20 | MbedBoy arduboy; |
| lmayencou | 0:649b2fe69f16 | 21 | |
| lmayencou | 0:649b2fe69f16 | 22 | // This function runs once in your game. |
| lmayencou | 0:649b2fe69f16 | 23 | // use it for anything that needs to be set only once in your game. |
| lmayencou | 0:649b2fe69f16 | 24 | void setup() { |
| lmayencou | 2:e3ef9f476913 | 25 | led2 = 1; |
| lmayencou | 2:e3ef9f476913 | 26 | |
| lmayencou | 0:649b2fe69f16 | 27 | // initiate arduboy instance |
| lmayencou | 1:c53e766082b4 | 28 | arduboy.start(); |
| lmayencou | 0:649b2fe69f16 | 29 | |
| lmayencou | 1:c53e766082b4 | 30 | arduboy.blank(); |
| lmayencou | 0:649b2fe69f16 | 31 | |
| lmayencou | 0:649b2fe69f16 | 32 | // here we set the framerate to 15, we do not need to run at |
| lmayencou | 0:649b2fe69f16 | 33 | // default 60 and it saves us battery life |
| lmayencou | 0:649b2fe69f16 | 34 | // arduboy.setFrameRate(15); |
| lmayencou | 0:649b2fe69f16 | 35 | } |
| lmayencou | 0:649b2fe69f16 | 36 | |
| lmayencou | 0:649b2fe69f16 | 37 | |
| lmayencou | 0:649b2fe69f16 | 38 | // our main game loop, this runs once every cycle/frame. |
| lmayencou | 0:649b2fe69f16 | 39 | // this is where our game logic goes. |
| lmayencou | 0:649b2fe69f16 | 40 | void loop() { |
| lmayencou | 0:649b2fe69f16 | 41 | // pause render until it's time for the next frame |
| lmayencou | 2:e3ef9f476913 | 42 | if (!(arduboy.nextFrame())) |
| lmayencou | 2:e3ef9f476913 | 43 | return; |
| lmayencou | 0:649b2fe69f16 | 44 | |
| lmayencou | 2:e3ef9f476913 | 45 | led2 = 0; |
| lmayencou | 0:649b2fe69f16 | 46 | // first we clear our screen to black |
| lmayencou | 1:c53e766082b4 | 47 | // arduboy.clear(); |
| lmayencou | 0:649b2fe69f16 | 48 | // wait_ms(2000); |
| lmayencou | 0:649b2fe69f16 | 49 | // we set our cursor 5 pixels to the right and 10 down from the top |
| lmayencou | 0:649b2fe69f16 | 50 | // (positions start at 0, 0) |
| lmayencou | 1:c53e766082b4 | 51 | arduboy.setTextCursor(1, 1); |
| lmayencou | 0:649b2fe69f16 | 52 | // then we print to screen what is in the Quotation marks "" |
| lmayencou | 2:e3ef9f476913 | 53 | arduboy.printf("Hello, world!"); |
| lmayencou | 0:649b2fe69f16 | 54 | // wait_ms(2000); |
| lmayencou | 0:649b2fe69f16 | 55 | |
| lmayencou | 1:c53e766082b4 | 56 | arduboy.drawCircle(30,30,30,WHITE); |
| lmayencou | 0:649b2fe69f16 | 57 | // then we finaly we tell the arduboy to display what we just wrote to the display |
| lmayencou | 1:c53e766082b4 | 58 | arduboy.display(); |
| lmayencou | 0:649b2fe69f16 | 59 | } |