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.
Dependencies: 4DGL-uLCD-SE PinDetect mbed
Revision 0:56c7173428ac, committed 2022-11-22
- Comitter:
- gboudreau6
- Date:
- Tue Nov 22 16:42:02 2022 +0000
- Commit message:
- For ECE 2036 Fall 2022 Lab 6;
Changed in this revision
diff -r 000000000000 -r 56c7173428ac 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Tue Nov 22 16:42:02 2022 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 000000000000 -r 56c7173428ac GettingStarted.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GettingStarted.html Tue Nov 22 16:42:02 2022 +0000 @@ -0,0 +1,16 @@ +<!DOCTYPE HTML> +<html lang="en-US"> + <head> + <meta charset="UTF-8"> + <meta http-equiv="refresh" + content="1;url="https://os.mbed.com/docs/latest/tools/exporting.html> + <script type="text/javascript"> + window.location.href = "https://os.mbed.com/docs/latest/tools/exporting.html" + </script> + <title>Page Redirection</title> + </head> + <body> + If you are not redirected automatically, please follow the + <a href='https://os.mbed.com/docs/v5.6/tools/exporting.html/'>link to the online exporter documentation</a> + </body> +</html>
diff -r 000000000000 -r 56c7173428ac PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Tue Nov 22 16:42:02 2022 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r 56c7173428ac TMP36.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36.h Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+//Setup a new class for TMP36 sensor
+class TMP36
+{
+public:
+ TMP36(PinName pin);
+ TMP36();
+ operator float ();
+ float read();
+private:
+//class sets up the AnalogIn pin
+ AnalogIn _pin;
+};
+
+TMP36::TMP36(PinName pin) : _pin(pin)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+
+float TMP36::read()
+{
+//convert sensor reading to temperature in degrees C
+ return ((_pin.read()*3.3)-0.500)*100.0;
+}
+//overload of float conversion (avoids needing to type .read() in equations)
+TMP36::operator float ()
+{
+//convert sensor reading to temperature in degrees C
+ return ((_pin.read()*3.3)-0.500)*100.0;
+}
\ No newline at end of file
diff -r 000000000000 -r 56c7173428ac gameJingle.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gameJingle.h Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,22 @@
+#ifndef STARTUPJINGLE_H
+#define STARTUPJINGLE_H
+
+#include "speaker.h"
+
+extern Speaker mySpeaker;
+
+class GameJingle
+{
+ public:
+
+ //move this to its own implementation file!!
+ void playIntro()
+ {
+ //make something a little better!!!!
+ mySpeaker.PlayNote(400.0,0.1,0.2);
+ }
+
+};
+
+
+#endif
diff -r 000000000000 -r 56c7173428ac gobbleBuzz.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gobbleBuzz.cpp Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,34 @@
+#include "gobbleBuzz.h"
+#include "uLCD_4DGL.h"
+
+
+#define TURKEY_HEIGHT 8
+#define TURKEY_WIDTH 11
+
+extern uLCD_4DGL uLCD;
+
+bool GobbleBuzz::overlap(int upperLX, int upperLY, int lowerRX, int lowerRY)
+{
+
+ int lrxpos = xpos+TURKEY_WIDTH;
+ int lrypos = ypos+TURKEY_HEIGHT;
+
+ //first check to see if in the upper left corner of turkey is in rectangle
+ if (((xpos >= upperLX) && (xpos <= lowerRX)) //then x pos satisfied
+ && ((ypos >= upperLY) && (ypos <=lowerRY)))
+ return true;
+ //now check to see if the lower right corner of the turkey is in the rectangle
+ else if ( ((lrxpos >= upperLX) && (lrxpos <= lowerRX)) //then x pos satisfied
+ && ((lrypos >= upperLY) && (lrypos <= lowerRY)) )
+ return true;
+ //now check to see if the upper right corner of turkey is in rectangle
+ else if ( ((lrxpos >= upperLX) && (lrxpos <= lowerRX)) //then x pos satisfied
+ && ((ypos >= upperLY) && (ypos <= lowerRY)) )
+ return true;
+ //now check to see if the lower left corner of the turkey is in rectangle
+ else if ( ((xpos >= upperLX) && (xpos <= lowerRX)) //then x pos satisfied
+ && ((lrypos >= upperLY) && (lrypos <= lowerRY)) )
+ return true;
+ else //no overlap
+ return false;
+}
\ No newline at end of file
diff -r 000000000000 -r 56c7173428ac gobbleBuzz.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gobbleBuzz.h Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,47 @@
+#ifndef GOBBLE_BUZZ_H
+#define GOBBLE_BUZZ
+
+//I am okay with keeping these
+//as define statements for the colors
+#define WHITE 0xFFFFFF
+#define BLACK 0x000000
+#define RED 0xFF0000
+#define GREEN 0x00FF00
+#define BLUE 0x0000FF
+#define LGREY 0xBFBFBF
+#define DGREY 0x5F5F5F
+#define YELLOW 0xFFFF00
+#define BROWN 0x964B00
+
+//Maybe these should be c++ constants
+//defined in your GobbleBuzz class!!
+#define X_DELTA 5
+#define Y_DELTA 5
+
+class GobbleBuzz
+{
+ public:
+ GobbleBuzz(): xpos(50), ypos(50) { copyX();copyY();}
+ inline void copyX(){ xOLDpos = xpos;}
+ inline void copyY() {yOLDpos = ypos;}
+ inline void increaseX() { xpos+=X_DELTA ;}
+ inline void increaseY() { ypos+=Y_DELTA;}
+ inline void decreaseX() { xpos-=X_DELTA; }
+ inline void decreaseY() { ypos-=Y_DELTA; }
+
+ bool overlap(int,int,int,int);
+
+ int getXPos() const { return xpos; }
+ int getYPos() const { return ypos; }
+ int getOLDXPos() const { return xOLDpos; }
+ int getOLDYPos() const {return yOLDpos; }
+
+ private:
+ int xpos;
+ int ypos;
+ int xOLDpos;
+ int yOLDpos;
+
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 56c7173428ac joystick.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick.cpp Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "joystick.h"
+
+
+Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire):
+ _pins(up, down, left, right, fire)
+{
+ _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
+ wait(0.001); //delays just a bit for pullups to pull inputs high
+}
+
+bool Nav_Switch::up()
+{
+ return !(_pins[0]);
+}
+bool Nav_Switch::down()
+{
+ return !(_pins[1]);
+}
+bool Nav_Switch::left()
+{
+ return !(_pins[2]);
+}
+bool Nav_Switch::right()
+{
+ return !(_pins[3]);
+}
+bool Nav_Switch::fire()
+{
+ return !(_pins[4]);
+}
+int Nav_Switch::read()
+{
+ return _pins.read();
+}
+Nav_Switch::operator int ()
+{
+ return _pins.read();
+}
\ No newline at end of file
diff -r 000000000000 -r 56c7173428ac joystick.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick.h Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,29 @@
+#ifndef JOYSTICK_H
+#define JOYSTICK_H
+
+#include "mbed.h"
+
+class Nav_Switch
+{
+public:
+ Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire);
+ int read();
+//boolean functions to test each switch
+ bool up();
+ bool down();
+ bool left();
+ bool right();
+ bool fire();
+//automatic read on RHS
+ operator int ();
+//index to any switch array style
+ bool operator[](int index) {
+ return _pins[index];
+ };
+private:
+ BusIn _pins;
+};
+
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 56c7173428ac main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,189 @@
+//Please note that you must transform this using a
+//polymorphic screen manage like we talked about
+//in the lab. This code is meant to be 'fixed'
+//and has some BAD programming choices; however,
+//it does show examples of specific mbed
+//functionality that you can use in your final GOOD program. :-)
+
+#include "mbed.h"
+#include "TMP36.h"
+#include "uLCD_4DGL.h"
+#include "PinDetect.h"
+#include "speaker.h"
+#include "joystick.h"
+#include "gameJingle.h"
+#include "gobbleBuzz.h"
+
+//Put this as C++ constant inside
+//your class that contains the turkey!!
+#define TURKEY_HEIGHT 8
+#define TURKEY_WIDTH 11
+
+#define _ BLACK
+#define X BROWN
+#define R RED
+#define Y YELLOW
+
+//sometimes putting in the global namespace and
+//static memory can be a little more efficient for
+//embedded programming
+
+int turkey_sprite[TURKEY_HEIGHT * TURKEY_WIDTH] = {
+ _,_,_,_,X,X,X,R,R,_,_,
+ _,X,X,X,X,X,X,X,R,Y,_,
+ X,X,X,X,X,_,_,X,X,Y,Y,
+ X,X,X,X,X,_,_,X,X,Y,_,
+ X,X,X,X,X,X,X,X,R,R,R,
+ _,_,_,X,X,_,X,X,_,_,_,
+ _,_,X,X,_,_,_,X,X,_,_,
+ X,X,_,_,_,X,_,_,_,X,X
+};
+
+
+uLCD_4DGL uLCD(p9, p10, p11); // create a global lcd object
+TMP36 myTMP36(p17);
+
+DigitalIn pb1(p21);
+DigitalIn pb2(p22);
+DigitalIn pb3(p23);
+
+Speaker mySpeaker(p25);
+
+Nav_Switch myNav(p16, p13, p14, p12, p15); //pin order on Sparkfun breakout
+
+int main() {
+
+ //Please have a startup and ending jingle. I provided
+ //a wimpy one note startup jingle
+ GameJingle Jingle;
+ GobbleBuzz buzz1;
+ Jingle.playIntro();
+
+ uLCD.cls();
+ //You can use this following command if you want landscape setup
+ //uLCD.display_control(LANDSCAPE);
+
+ //This time(0) should return the number of seconds that the mbed
+ //has been powered on.
+ srand(time(0));
+
+ //if you are not getting random numbers after each reset try debugging with
+ //uLCD.printf("Time(0)=%i\n",time(0));
+
+ //setup push buttons
+ pb1.mode(PullUp);
+ pb2.mode(PullUp);
+ pb3.mode(PullUp);
+ wait(0.3); //This can make the system more stable as it sets up the pins
+
+ //If you don't have this your system will be really slow.
+ //This sets the communication rate between the uLCD and the
+ //mbed system.
+ uLCD.baudrate(300000);
+ wait(0.3); //Always good to wait as mbed system set itself up!
+
+
+ //let's draw a border around the screen in a festive GREEN
+ //NOTE: In your program make sure the turkey is prevented from
+ //going outside the bounds set by this boarder!!
+ uLCD.cls(); //This clears the screen
+ uLCD.rectangle(0,0,120,110,GREEN);
+
+ //In this sample program I have one square that randomly
+ //changes position after it is gobbled up by the gobbler!
+ //In your program you will have various choices for
+ //your turkey to eat!
+ int randXPos = (rand()%(118-TURKEY_WIDTH))+2;
+ int randYPos = (rand()%(108-TURKEY_HEIGHT))+2;
+
+ int points = 0; //this will keep track of the number of times the
+ //turkey eats the square.
+
+ //In your game you will have to keep track of points in
+ //a more complex scoring scenario; however, this illustrates
+ //a way that you can put text anywhere on the screen! In this
+ //case it is the number of times the turkey eats the square.
+ //NOTE: The locate function coordinates are not in units of pixels
+ //but in units of the size of the character printed.
+
+ uLCD.text_width(1); //You can change the size of your text if you want
+ uLCD.text_height(1); //using these member functions for uLCD
+ uLCD.locate(1,14); //units are not pixels but character sizes
+ uLCD.printf("%i",points); //This will print out the points at bottom of screen
+
+ bool GETOUT = false;
+ int color = WHITE;
+
+ while(!GETOUT)
+ {
+ //You can read about this in the lab. Allows quick printing of graphic sprites
+ uLCD.BLIT(buzz1.getXPos(), buzz1.getYPos(), TURKEY_WIDTH, TURKEY_HEIGHT, turkey_sprite);
+
+ //This is what the turkey 'eats'. This is so boring; you must spice up the game!
+ uLCD.filled_rectangle(randXPos, randYPos,randXPos+TURKEY_WIDTH, randYPos+TURKEY_HEIGHT,color);
+
+ //In order to make the sprite move I must keep track of the old
+ //position before it is changed by maneveurs on the joystick
+ buzz1.copyX();
+ buzz1.copyY();
+
+ //Here is an example on how you can use the joystick using the joystick.h
+ //You might want to put in a move() function for the GobbleBuzz
+ if (myNav.up()) buzz1.increaseY();
+ if (myNav.down()) buzz1.decreaseY();
+ if (myNav.left()) buzz1.increaseX();
+ if (myNav.right()) buzz1.decreaseX();
+ if (myNav.fire()) { GETOUT = true; }
+
+ //You can change the color of your square with the push
+ //buttons. Notice how they are used because they are in
+ //a pull up configuration
+ if (!pb1) { color = WHITE; }
+ if (!pb2) {color = BLUE; }
+ if (!pb3) {color = GREEN; }
+
+ //Here is an example of the turkey 'eating' the square
+ //IDEA: If the turkey sprite and the retangle sprite intersect
+ //then delete the rectanglar "food" and randomly draw in another
+ //location.
+ if (buzz1.overlap(randXPos, randYPos, randXPos+TURKEY_WIDTH, randYPos+TURKEY_HEIGHT))
+ //then you need to delete retangle and redraw in another place
+ {
+ //Note I had the edible rectangle and the turkey sprite be the same
+ //size, but you do not have to do this.
+ uLCD.filled_rectangle(randXPos, randYPos,randXPos+TURKEY_WIDTH, randYPos+TURKEY_HEIGHT,BLACK);
+
+ //See if you can make a better gobble sound than this!
+ mySpeaker.PlayNote(450.0,0.1,0.2);
+
+ //Here I pick a new location of the eatable rectangle
+ randXPos = (rand()%(118-TURKEY_WIDTH))+2;
+ randYPos = (rand()%(108-TURKEY_HEIGHT))+2;
+
+ //now update the score. Looks like a cut and paste job...
+ //make make it a function!!
+ uLCD.locate(1,14);
+ uLCD.text_width(1);
+ uLCD.text_height(1);
+ uLCD.printf("%i",++points);
+ }
+
+ //This will smooth out the movement of your zoombie turkey
+ wait(0.1);
+
+ //If the turkey has been moved with the joystick then you need
+ //to delete its image at the old location. At the beginning of the loop
+ //the turkey sprite will be redrawn again!
+ if (( buzz1.getXPos() != buzz1.getOLDXPos()) || (buzz1.getYPos() != buzz1.getOLDYPos()))
+ uLCD.filled_rectangle(buzz1.getOLDXPos(), buzz1.getOLDYPos(),
+ buzz1.getOLDXPos()+TURKEY_WIDTH, buzz1.getOLDYPos()+ TURKEY_HEIGHT, BLACK);
+
+ }
+
+ //Print a final farewell to indicate win or loss. Also have a nice closing jingle for
+ //your game!
+ uLCD.cls();
+ uLCD.printf("\n\n\n\n\n Happy \n Thanksgiving \n Break!!");
+
+
+}
diff -r 000000000000 -r 56c7173428ac mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Nov 22 16:42:02 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
diff -r 000000000000 -r 56c7173428ac mbed_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_config.h Tue Nov 22 16:42:02 2022 +0000 @@ -0,0 +1,55 @@ +/* + * mbed SDK + * Copyright (c) 2017 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Automatically generated configuration file. +// DO NOT EDIT, content will be overwritten. + +#ifndef __MBED_CONFIG_DATA__ +#define __MBED_CONFIG_DATA__ + +// Configuration parameters +#define MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_CTHUNK_COUNT_MAX 8 // set by library:platform +#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 9600 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR "\nFor more info, visit: https://armmbed.github.io/mbedos-error/?error=0x%08X" // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_HIST_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE 4 // set by library:platform +#define MBED_CONF_PLATFORM_ERROR_REBOOT_MAX 1 // set by library:platform +#define MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED 0 // set by library:platform +#define MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR 0 // set by library:platform +#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN 16 // set by library:platform +#define MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE 9600 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES 0 // set by library:platform +#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT 1 // set by library:platform +#define MBED_CONF_PLATFORM_USE_MPU 1 // set by library:platform +#define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x1000 // set by target:Target +#define MBED_CONF_TARGET_CONSOLE_UART 1 // set by target:Target +#define MBED_CONF_TARGET_DEEP_SLEEP_LATENCY 0 // set by target:Target +#define MBED_CONF_TARGET_DEFAULT_ADC_VREF NAN // set by target:Target +#define MBED_CONF_TARGET_INIT_US_TICKER_AT_BOOT 0 // set by target:Target +#define MBED_CONF_TARGET_MPU_ROM_END 0x0fffffff // set by target:Target +#define MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE ETHERNET // set by target:LPC1768 +#define MBED_CONF_TARGET_TICKLESS_FROM_US_TICKER 0 // set by target:Target +#define MBED_CONF_TARGET_US_TICKER_TIMER 3 // set by target:LPC1768 +#define MBED_CONF_TARGET_XIP_ENABLE 0 // set by target:Target + +#endif
diff -r 000000000000 -r 56c7173428ac speaker.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/speaker.h Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,25 @@
+#ifndef SPEAKER_H
+#define SPEAKER_H
+
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+class Speaker
+{
+public:
+ Speaker(PinName pin) : _pin(pin) {
+ // _pin(pin) means pass pin to the Speaker Constructor
+ }
+
+ // class method to play a note based on PwmOut class
+ void PlayNote(float frequency, float duration, float volume) {
+ _pin.period(1.0/frequency);
+ _pin = volume/2.0;
+ wait(duration);
+ _pin = 0.0;
+ }
+
+private:
+ PwmOut _pin;
+};
+
+#endif
\ No newline at end of file