updated 7seg controls for new 7 seg boards

Dependencies:   PixelArray WS2812 mbed

Fork of frdm_pong_table_controller by Demo Team

Committer:
DanGibbons
Date:
Wed Jul 05 15:23:44 2017 +0000
Revision:
4:2e80bd814f57
Child:
5:2d439ccefc7d
Added main.h; Added figure of 8 animation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DanGibbons 4:2e80bd814f57 1 #include "mbed.h"
DanGibbons 4:2e80bd814f57 2 #include "WS2812.h"
DanGibbons 4:2e80bd814f57 3 #include "PixelArray.h"
DanGibbons 4:2e80bd814f57 4
DanGibbons 4:2e80bd814f57 5 #define WS2812_BUF 122
DanGibbons 4:2e80bd814f57 6 #define NUM_COLORS 6
DanGibbons 4:2e80bd814f57 7 #define NUM_LEDS_PER_COLOR 1
DanGibbons 4:2e80bd814f57 8
DanGibbons 4:2e80bd814f57 9 //-------- Colours -----------
DanGibbons 4:2e80bd814f57 10 #define RED 0x2f0000
DanGibbons 4:2e80bd814f57 11 #define YELLOW 0x2f2f00
DanGibbons 4:2e80bd814f57 12 #define GREEN 0x002f00
DanGibbons 4:2e80bd814f57 13 #define LIGHTBLUE 0x002f2f
DanGibbons 4:2e80bd814f57 14 #define DARKBLUE 0x00002f
DanGibbons 4:2e80bd814f57 15 #define BLUE 0x0000ff // Player scored a goal
DanGibbons 4:2e80bd814f57 16 #define PINK 0x2f002f
DanGibbons 4:2e80bd814f57 17 #define OFF 0x000000
DanGibbons 4:2e80bd814f57 18 #define WHITE 0xffffaa
DanGibbons 4:2e80bd814f57 19 #define ARMBLUE 0x128BAB
DanGibbons 4:2e80bd814f57 20 #define PURPLE 0xff0055 // Player has conceded a goal
DanGibbons 4:2e80bd814f57 21
DanGibbons 4:2e80bd814f57 22 // Goal Sensors
DanGibbons 4:2e80bd814f57 23 AnalogIn robotBreakBeam(A0);
DanGibbons 4:2e80bd814f57 24 AnalogIn playerBreakBeam(A1);
DanGibbons 4:2e80bd814f57 25
DanGibbons 4:2e80bd814f57 26 // K64F On-board LED
DanGibbons 4:2e80bd814f57 27 DigitalOut led_green(LED_GREEN, 1);
DanGibbons 4:2e80bd814f57 28
DanGibbons 4:2e80bd814f57 29 //K64F On-board Switches
DanGibbons 4:2e80bd814f57 30 DigitalIn PB1(PTC6);
DanGibbons 4:2e80bd814f57 31 DigitalIn PB2(PTA4);
DanGibbons 4:2e80bd814f57 32
DanGibbons 4:2e80bd814f57 33 // SERIAL
DanGibbons 4:2e80bd814f57 34 Serial pc(USBTX, USBRX); // tx, rx
DanGibbons 4:2e80bd814f57 35
DanGibbons 4:2e80bd814f57 36 // LED STRIPS
DanGibbons 4:2e80bd814f57 37 // See the program page for information on the timing numbers
DanGibbons 4:2e80bd814f57 38 // The given numbers are for the K64F
DanGibbons 4:2e80bd814f57 39 WS2812 robotScoreLED(D3, WS2812_BUF, 0, 5, 5, 0);
DanGibbons 4:2e80bd814f57 40 WS2812 playerScoreLED(D5,WS2812_BUF, 0, 5, 5, 0);
DanGibbons 4:2e80bd814f57 41 PixelArray robotScorePx(WS2812_BUF);
DanGibbons 4:2e80bd814f57 42 PixelArray playerScorePx(WS2812_BUF);
DanGibbons 4:2e80bd814f57 43
DanGibbons 4:2e80bd814f57 44
DanGibbons 4:2e80bd814f57 45 // LED Variables
DanGibbons 4:2e80bd814f57 46 bool seg1A, seg1B, seg1C, seg1D, seg1E, seg1F, seg1G;
DanGibbons 4:2e80bd814f57 47 //int seg1Array[122];
DanGibbons 4:2e80bd814f57 48 int mainArray[11][122];
DanGibbons 4:2e80bd814f57 49
DanGibbons 4:2e80bd814f57 50 // Score counters
DanGibbons 4:2e80bd814f57 51 int robotScore;
DanGibbons 4:2e80bd814f57 52 int playerScore;
DanGibbons 4:2e80bd814f57 53 int scoreLimit = 3;
DanGibbons 4:2e80bd814f57 54 bool finishedGame = false;
DanGibbons 4:2e80bd814f57 55 int endFlashes = 3;
DanGibbons 4:2e80bd814f57 56 int numFlashes;
DanGibbons 4:2e80bd814f57 57
DanGibbons 4:2e80bd814f57 58 // Robot Bream Beam value
DanGibbons 4:2e80bd814f57 59 double prevRbbValue; // Previous Robot break beam value
DanGibbons 4:2e80bd814f57 60 double prevPbbValue; // Previous player break beam value
DanGibbons 4:2e80bd814f57 61
DanGibbons 4:2e80bd814f57 62 // FUNCTION DECLERATIONS
DanGibbons 4:2e80bd814f57 63 void Setup();
DanGibbons 4:2e80bd814f57 64 void SetNumberPatterns();
DanGibbons 4:2e80bd814f57 65 void SetFigureOf8Pattern();
DanGibbons 4:2e80bd814f57 66 void SetLEDArray(int x);
DanGibbons 4:2e80bd814f57 67 void WriteScores();
DanGibbons 4:2e80bd814f57 68 void HandleGoal(bool hasRobotScored);
DanGibbons 4:2e80bd814f57 69 void WritePxScores(int line_num, bool isRobot);
DanGibbons 4:2e80bd814f57 70 void WritePxGoal(unsigned int colour,bool isRobot);
DanGibbons 4:2e80bd814f57 71 void HandleWin();
DanGibbons 4:2e80bd814f57 72 void GoalAnimation(bool hasRobotScored);
DanGibbons 4:2e80bd814f57 73 void WinAnimation(bool isRobotWinner);
DanGibbons 4:2e80bd814f57 74 void FigureOf8Animation();