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