Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Drawing faces on button press using template by MIKE SPIVEY
- // AARON OMOTOSHO
- #include "hardware.h"
- /* delay -- pause for n microseconds */
- void delay(unsigned n) {
- unsigned t = n << 1;
- while (t > 0) {
- // 500nsec per iteration at 16MHz
- nop(); nop(); nop();
- t--;
- }
- }
- static const unsigned smile[] = {
- 0x3070, 0x59f0, 0x9ae0
- };
- static const unsigned frown[] = {
- 0x38f0, 0x59f0, 0x9a80
- };
- static const unsigned spot[] = {
- 0x0000, 0x5fb0, 0x0000
- };
- static const unsigned nought[] = {
- 0x0000, 0x0000, 0x0000
- };
- /* show -- display three rows of a picture n times */
- void show(const unsigned *img, int n) {
- while (n-- > 0) {
- // Takes 15msec per iteration
- for (int p = 0; p < 3; p++) {
- GPIO_OUT = img[p];
- delay(5000);
- }
- }
- }
- int a_pressed(void) {
- return (GPIO_IN & 0x20000) != 0x20000;
- }
- int b_pressed(void) {
- return (GPIO_IN & 0x4000000) != 0x4000000;
- }
- void init(void) {
- GPIO_DIR = 0xfff0;
- GPIO_PINCNF[BUTTON_A] = 0;
- GPIO_PINCNF[BUTTON_B] = 0;
- while (1) {
- if (a_pressed()) {
- show(frown, 1);
- } else if (b_pressed()){
- show(smile, 1);
- } else {
- show(spot, 10);
- show(nought, 10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement