updated 7seg controls for new 7 seg boards
Dependencies: PixelArray WS2812 mbed
Fork of frdm_pong_table_controller by
main.h@9:f3f194982bb3, 2017-07-11 (annotated)
- Committer:
- DanGibbons
- Date:
- Tue Jul 11 13:02:44 2017 +0000
- Revision:
- 9:f3f194982bb3
- Parent:
- 8:66dac2e00cce
- Child:
- 10:554301a1579b
Improved button behaviour.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DanGibbons | 5:2d439ccefc7d | 1 | #ifndef MAIN_H |
DanGibbons | 5:2d439ccefc7d | 2 | #define MAIN_H |
DanGibbons | 5:2d439ccefc7d | 3 | |
DanGibbons | 4:2e80bd814f57 | 4 | #include "mbed.h" |
DanGibbons | 4:2e80bd814f57 | 5 | #include "WS2812.h" |
DanGibbons | 4:2e80bd814f57 | 6 | #include "PixelArray.h" |
DanGibbons | 4:2e80bd814f57 | 7 | |
DanGibbons | 4:2e80bd814f57 | 8 | #define WS2812_BUF 122 |
DanGibbons | 4:2e80bd814f57 | 9 | #define NUM_COLORS 6 |
DanGibbons | 4:2e80bd814f57 | 10 | #define NUM_LEDS_PER_COLOR 1 |
DanGibbons | 4:2e80bd814f57 | 11 | |
DanGibbons | 4:2e80bd814f57 | 12 | //-------- Colours ----------- |
DanGibbons | 4:2e80bd814f57 | 13 | #define RED 0x2f0000 |
DanGibbons | 4:2e80bd814f57 | 14 | #define YELLOW 0x2f2f00 |
DanGibbons | 4:2e80bd814f57 | 15 | #define GREEN 0x002f00 |
DanGibbons | 4:2e80bd814f57 | 16 | #define LIGHTBLUE 0x002f2f |
DanGibbons | 4:2e80bd814f57 | 17 | #define DARKBLUE 0x00002f |
DanGibbons | 4:2e80bd814f57 | 18 | #define BLUE 0x0000ff // Player scored a goal |
DanGibbons | 4:2e80bd814f57 | 19 | #define PINK 0x2f002f |
DanGibbons | 4:2e80bd814f57 | 20 | #define OFF 0x000000 |
DanGibbons | 4:2e80bd814f57 | 21 | #define WHITE 0xffffaa |
DanGibbons | 4:2e80bd814f57 | 22 | #define ARMBLUE 0x128BAB |
DanGibbons | 4:2e80bd814f57 | 23 | #define PURPLE 0xff0055 // Player has conceded a goal |
DanGibbons | 4:2e80bd814f57 | 24 | |
DanGibbons | 4:2e80bd814f57 | 25 | // Goal Sensors |
DanGibbons | 4:2e80bd814f57 | 26 | AnalogIn robotBreakBeam(A0); |
DanGibbons | 4:2e80bd814f57 | 27 | AnalogIn playerBreakBeam(A1); |
DanGibbons | 4:2e80bd814f57 | 28 | |
DanGibbons | 4:2e80bd814f57 | 29 | // K64F On-board LED |
DanGibbons | 4:2e80bd814f57 | 30 | DigitalOut led_green(LED_GREEN, 1); |
DanGibbons | 4:2e80bd814f57 | 31 | |
DanGibbons | 4:2e80bd814f57 | 32 | //K64F On-board Switches |
DanGibbons | 4:2e80bd814f57 | 33 | DigitalIn PB1(PTC6); |
DanGibbons | 4:2e80bd814f57 | 34 | DigitalIn PB2(PTA4); |
DanGibbons | 7:dc6f1f105c52 | 35 | InterruptIn idleButton(PTC11); |
DanGibbons | 4:2e80bd814f57 | 36 | |
DanGibbons | 4:2e80bd814f57 | 37 | // SERIAL |
DanGibbons | 7:dc6f1f105c52 | 38 | RawSerial pc(USBTX, USBRX); // tx, rx |
DanGibbons | 4:2e80bd814f57 | 39 | |
DanGibbons | 4:2e80bd814f57 | 40 | // LED STRIPS |
DanGibbons | 4:2e80bd814f57 | 41 | // See the program page for information on the timing numbers |
DanGibbons | 4:2e80bd814f57 | 42 | // The given numbers are for the K64F |
DanGibbons | 4:2e80bd814f57 | 43 | WS2812 robotScoreLED(D3, WS2812_BUF, 0, 5, 5, 0); |
DanGibbons | 4:2e80bd814f57 | 44 | WS2812 playerScoreLED(D5,WS2812_BUF, 0, 5, 5, 0); |
DanGibbons | 4:2e80bd814f57 | 45 | PixelArray robotScorePx(WS2812_BUF); |
DanGibbons | 4:2e80bd814f57 | 46 | PixelArray playerScorePx(WS2812_BUF); |
DanGibbons | 4:2e80bd814f57 | 47 | |
DanGibbons | 4:2e80bd814f57 | 48 | |
DanGibbons | 4:2e80bd814f57 | 49 | // LED Variables |
DanGibbons | 4:2e80bd814f57 | 50 | bool seg1A, seg1B, seg1C, seg1D, seg1E, seg1F, seg1G; |
DanGibbons | 4:2e80bd814f57 | 51 | int mainArray[11][122]; |
DanGibbons | 5:2d439ccefc7d | 52 | int rand_colors[] = {0x00FF00, 0x7FFF00, 0xFFFF00, 0xFF7F00, 0xFF0000, 0xFE00FF, 0x7F00FF, 0x0000FF, 0x007FFF, 0x00FFFE, 0x00FF7F}; |
DanGibbons | 4:2e80bd814f57 | 53 | |
DanGibbons | 4:2e80bd814f57 | 54 | // Score counters |
DanGibbons | 4:2e80bd814f57 | 55 | int robotScore; |
DanGibbons | 4:2e80bd814f57 | 56 | int playerScore; |
DanGibbons | 4:2e80bd814f57 | 57 | int scoreLimit = 3; |
DanGibbons | 4:2e80bd814f57 | 58 | bool finishedGame = false; |
DanGibbons | 4:2e80bd814f57 | 59 | int endFlashes = 3; |
DanGibbons | 4:2e80bd814f57 | 60 | int numFlashes; |
DanGibbons | 4:2e80bd814f57 | 61 | |
DanGibbons | 6:5e8e2645cd93 | 62 | // Flags |
DanGibbons | 6:5e8e2645cd93 | 63 | volatile int idle_flag = 0; |
DanGibbons | 7:dc6f1f105c52 | 64 | volatile int idle_button_pressed = 0; |
DanGibbons | 6:5e8e2645cd93 | 65 | |
DanGibbons | 4:2e80bd814f57 | 66 | // Robot Bream Beam value |
DanGibbons | 4:2e80bd814f57 | 67 | double prevRbbValue; // Previous Robot break beam value |
DanGibbons | 4:2e80bd814f57 | 68 | double prevPbbValue; // Previous player break beam value |
DanGibbons | 4:2e80bd814f57 | 69 | |
DanGibbons | 4:2e80bd814f57 | 70 | // FUNCTION DECLERATIONS |
DanGibbons | 9:f3f194982bb3 | 71 | void Setup(); |
DanGibbons | 6:5e8e2645cd93 | 72 | void SetNumberPatterns(); // sets segment patterns for numbers |
DanGibbons | 6:5e8e2645cd93 | 73 | void SetLEDArray(int x); // sets segment patterns in mainArray |
DanGibbons | 8:66dac2e00cce | 74 | void WriteScores(); // writes scores to the LEDs |
DanGibbons | 6:5e8e2645cd93 | 75 | void WritePxAnimation(int line_num,bool isRobot,bool colour); // writes mainArray to either LED buffer in blue or random colours |
DanGibbons | 6:5e8e2645cd93 | 76 | |
DanGibbons | 9:f3f194982bb3 | 77 | // Protocols for handling goals and whether the player or robot has won |
DanGibbons | 6:5e8e2645cd93 | 78 | void HandleGoal(bool hasRobotScored); |
DanGibbons | 4:2e80bd814f57 | 79 | void HandleWin(); |
DanGibbons | 6:5e8e2645cd93 | 80 | |
DanGibbons | 9:f3f194982bb3 | 81 | // Animation for scoring a goal and winning the game |
DanGibbons | 4:2e80bd814f57 | 82 | void GoalAnimation(bool hasRobotScored); |
DanGibbons | 4:2e80bd814f57 | 83 | void WinAnimation(bool isRobotWinner); |
DanGibbons | 6:5e8e2645cd93 | 84 | |
DanGibbons | 9:f3f194982bb3 | 85 | // Decorative Animations |
DanGibbons | 6:5e8e2645cd93 | 86 | void CircleAnimation(bool robot, bool robotColour,bool player, bool playerColour, int numberOfRepitions); |
DanGibbons | 9:f3f194982bb3 | 87 | void FigureOf8Animation(bool robot, bool robotColour,bool player, bool playerColour, int numberOfRepitions); |
DanGibbons | 9:f3f194982bb3 | 88 | void DrainAnimation(bool robot, bool robotColour, bool player, bool playerColour); |
DanGibbons | 5:2d439ccefc7d | 89 | |
DanGibbons | 9:f3f194982bb3 | 90 | // Animations for writing and deleting displayed numbers |
DanGibbons | 6:5e8e2645cd93 | 91 | void ZeroInAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 92 | void ZeroOutAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 93 | void OneInAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 94 | void OneOutAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 95 | void TwoInAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 96 | void TwoOutAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 97 | void ThreeInAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 98 | void ThreeOutAnimation(bool robot, bool robotColour,bool player, bool playerColour); |
DanGibbons | 6:5e8e2645cd93 | 99 | |
DanGibbons | 9:f3f194982bb3 | 100 | // Protocol and transition functions for Idle and Play states |
DanGibbons | 9:f3f194982bb3 | 101 | void IdleStateProtocol(); |
DanGibbons | 9:f3f194982bb3 | 102 | void PlayStateProtocol(); |
DanGibbons | 7:dc6f1f105c52 | 103 | void PlayToIdleTransition(); |
DanGibbons | 7:dc6f1f105c52 | 104 | void IdleToPlayTransition(); |
DanGibbons | 7:dc6f1f105c52 | 105 | |
DanGibbons | 6:5e8e2645cd93 | 106 | // ISRs |
DanGibbons | 6:5e8e2645cd93 | 107 | void idleButtonISR(); |
DanGibbons | 6:5e8e2645cd93 | 108 | |
DanGibbons | 6:5e8e2645cd93 | 109 | |
DanGibbons | 5:2d439ccefc7d | 110 | #endif |