Simple drag n drop of old project
No further commits, archival only.
This commit is contained in:
39
include/README
Normal file
39
include/README
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
46
lib/README
Normal file
46
lib/README
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
15
platformio.ini
Normal file
15
platformio.ini
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:genericSTM32F103C8]
|
||||||
|
platform = ststm32
|
||||||
|
board = genericSTM32F103C8
|
||||||
|
framework = arduino
|
||||||
|
debug_tool = stlink
|
||||||
422
src/main.cpp
Normal file
422
src/main.cpp
Normal file
@@ -0,0 +1,422 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define SER PB0
|
||||||
|
#define OE PA7
|
||||||
|
#define RCLK PA6
|
||||||
|
#define SRCLK PA5
|
||||||
|
#define SRCLR PA4
|
||||||
|
#define BUTTON PA0
|
||||||
|
#define BLANK 0
|
||||||
|
#define LETHAL 1
|
||||||
|
#define DEALER_LED PB11
|
||||||
|
#define PLAYER_LED PB15
|
||||||
|
|
||||||
|
unsigned int totalHealth;
|
||||||
|
unsigned int roundCount = 1;
|
||||||
|
bool turn;
|
||||||
|
unsigned int numberOfBlanks;
|
||||||
|
unsigned int numberOfLethals;
|
||||||
|
unsigned int totalShellCount;
|
||||||
|
unsigned int dealerHealth;
|
||||||
|
unsigned int playerHealth;
|
||||||
|
bool inRoundCount;
|
||||||
|
bool roundCleared = true;
|
||||||
|
int shellCount;
|
||||||
|
char blankshells[4] = {PB12, PB13, PB14, PA8};
|
||||||
|
char liveshells[4] = {PB9, PA9 ,PB5, PB6};
|
||||||
|
char shellOrder[8] = {5, 5, 5, 5, 5, 5, 5, 5};
|
||||||
|
|
||||||
|
void updatePlayersHealth()
|
||||||
|
{
|
||||||
|
byte playerHealthHalfBit;
|
||||||
|
byte dealerHealthHalfBit;
|
||||||
|
switch(playerHealth)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
playerHealthHalfBit = 0x8;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
playerHealthHalfBit = 0xC;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
playerHealthHalfBit = 0xE;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
playerHealthHalfBit = 0xF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch(dealerHealth)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
dealerHealthHalfBit = 0x8;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dealerHealthHalfBit = 0xC;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
dealerHealthHalfBit = 0xE;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
dealerHealthHalfBit = 0xF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
shiftOut(SER, SRCLK, LSBFIRST, (dealerHealthHalfBit << 4) | playerHealthHalfBit);
|
||||||
|
digitalWrite(RCLK, 1);
|
||||||
|
digitalWrite(RCLK, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawPlayersHealth()
|
||||||
|
{
|
||||||
|
totalHealth = random(2,5);
|
||||||
|
dealerHealth = totalHealth;
|
||||||
|
playerHealth = totalHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tellRoundCount()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 4; i ++)
|
||||||
|
{
|
||||||
|
switch(roundCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
shiftOut(SER, SRCLK, LSBFIRST, 0x88);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
shiftOut(SER, SRCLK, LSBFIRST, 0xCC);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
shiftOut(SER, SRCLK, LSBFIRST, 0xEE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
digitalWrite(RCLK, HIGH);
|
||||||
|
digitalWrite(RCLK, LOW);
|
||||||
|
delay(500);
|
||||||
|
shiftOut(SER, SRCLK, LSBFIRST, 0x00);
|
||||||
|
digitalWrite(RCLK, HIGH);
|
||||||
|
digitalWrite(RCLK, LOW);
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showBullets()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < numberOfBlanks; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(blankshells[i], 1);
|
||||||
|
}
|
||||||
|
for(int j = 0; j < numberOfLethals; j++)
|
||||||
|
{
|
||||||
|
digitalWrite(liveshells[j], 1);
|
||||||
|
}
|
||||||
|
delay(3000);
|
||||||
|
for(int x = 0; x < 4; x++)
|
||||||
|
{
|
||||||
|
digitalWrite(liveshells[x], 0);
|
||||||
|
digitalWrite(blankshells[x], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateTurnLights()
|
||||||
|
{
|
||||||
|
if (turn == false)
|
||||||
|
{
|
||||||
|
digitalWrite(PLAYER_LED, 1);
|
||||||
|
digitalWrite(DEALER_LED, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite(DEALER_LED, 1);
|
||||||
|
digitalWrite(PLAYER_LED, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void insertBullets()
|
||||||
|
{
|
||||||
|
numberOfBlanks = 0;
|
||||||
|
numberOfLethals = 0;
|
||||||
|
totalShellCount = random(2, 9);
|
||||||
|
for (int i = 0; i < totalShellCount; i++)
|
||||||
|
{
|
||||||
|
shellOrder[i] = random(2);
|
||||||
|
}
|
||||||
|
for (int a = 0; a < totalShellCount; a++)
|
||||||
|
{
|
||||||
|
bool shellType = shellOrder[a];
|
||||||
|
if (shellType == BLANK)
|
||||||
|
{
|
||||||
|
numberOfBlanks++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
numberOfLethals++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shellCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void blinkYourself(bool state)
|
||||||
|
{
|
||||||
|
if (state == false)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(PLAYER_LED, 1);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(PLAYER_LED, 0);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(DEALER_LED, 1);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(DEALER_LED, 0);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fireBlank()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(blankshells[i], 1);
|
||||||
|
}
|
||||||
|
delay(200);
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(blankshells[i], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fireLive()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(liveshells[i], 1);
|
||||||
|
}
|
||||||
|
delay(200);
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(liveshells[i], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void roundPlay()
|
||||||
|
{
|
||||||
|
if (turn == false)
|
||||||
|
{
|
||||||
|
while (digitalRead(BUTTON) != 1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
if (digitalRead(BUTTON) != 1) //player shoots dealer
|
||||||
|
{
|
||||||
|
if (shellOrder[shellCount] == BLANK)
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
dealerHealth--;
|
||||||
|
fireLive();
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blinkYourself(false);
|
||||||
|
if(shellOrder[shellCount] == BLANK) //player shoots himself
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
playerHealth--;
|
||||||
|
fireLive();
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (numberOfBlanks > numberOfLethals) //dealer shoots himself
|
||||||
|
{
|
||||||
|
blinkYourself(true);
|
||||||
|
delay(1000);
|
||||||
|
if (shellOrder[shellCount] == BLANK)
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
fireLive();
|
||||||
|
dealerHealth--;
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (numberOfBlanks == numberOfLethals) //random draw
|
||||||
|
{
|
||||||
|
unsigned int freedomOfChoise = random(2);
|
||||||
|
if (freedomOfChoise == 0) // dealer randomly shoots player
|
||||||
|
{
|
||||||
|
if(shellOrder[shellCount] == BLANK)
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
fireLive();
|
||||||
|
playerHealth--;
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //dealer randomly shoots himself
|
||||||
|
{
|
||||||
|
blinkYourself(true);
|
||||||
|
delay(1000);
|
||||||
|
if (shellOrder[shellCount] == BLANK)
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
fireLive();
|
||||||
|
dealerHealth--;
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //dealer shoots player
|
||||||
|
{
|
||||||
|
if(shellOrder[shellCount] == BLANK)
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfBlanks--;
|
||||||
|
fireBlank();
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shellCount++;
|
||||||
|
numberOfLethals--;
|
||||||
|
fireLive();
|
||||||
|
playerHealth--;
|
||||||
|
turn = !turn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatePlayersHealth();
|
||||||
|
updateTurnLights();
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkHealth()
|
||||||
|
{
|
||||||
|
if (playerHealth == 0)
|
||||||
|
{
|
||||||
|
roundCount = 1;
|
||||||
|
roundCleared = true;
|
||||||
|
}
|
||||||
|
if (dealerHealth == 0)
|
||||||
|
{
|
||||||
|
roundCount++;
|
||||||
|
roundCleared = true;
|
||||||
|
}
|
||||||
|
if ((numberOfBlanks + numberOfLethals == 0))
|
||||||
|
{
|
||||||
|
inRoundCount = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
pinMode(SER, OUTPUT);
|
||||||
|
pinMode(OE, OUTPUT);
|
||||||
|
pinMode(RCLK, OUTPUT);
|
||||||
|
pinMode(SRCLK, OUTPUT);
|
||||||
|
pinMode(SRCLR, OUTPUT);
|
||||||
|
pinMode(DEALER_LED, OUTPUT);
|
||||||
|
pinMode(PLAYER_LED, OUTPUT);
|
||||||
|
pinMode(BUTTON, INPUT_PULLDOWN);
|
||||||
|
pinMode(PB2, OUTPUT);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
pinMode(blankshells[i], OUTPUT);
|
||||||
|
pinMode(liveshells[i], OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(OE, LOW);
|
||||||
|
digitalWrite(SRCLR, HIGH);
|
||||||
|
|
||||||
|
randomSeed(analogRead(PB1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (roundCleared == true)
|
||||||
|
{
|
||||||
|
digitalWrite(PLAYER_LED, 0);
|
||||||
|
digitalWrite(DEALER_LED, 0);
|
||||||
|
turn = false;
|
||||||
|
tellRoundCount();
|
||||||
|
drawPlayersHealth();
|
||||||
|
updatePlayersHealth();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
insertBullets();
|
||||||
|
} while (numberOfBlanks > (totalShellCount / 2) || numberOfLethals > (totalShellCount / 2));
|
||||||
|
showBullets();
|
||||||
|
updateTurnLights();
|
||||||
|
inRoundCount = false;
|
||||||
|
roundCleared = false;
|
||||||
|
}
|
||||||
|
if (inRoundCount == true)
|
||||||
|
{
|
||||||
|
digitalWrite(PLAYER_LED, 0);
|
||||||
|
digitalWrite(DEALER_LED, 0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
insertBullets();
|
||||||
|
} while (numberOfBlanks > (totalShellCount / 2) || numberOfLethals > (totalShellCount / 2));
|
||||||
|
showBullets();
|
||||||
|
turn = false;
|
||||||
|
updateTurnLights();
|
||||||
|
inRoundCount = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
roundPlay();
|
||||||
|
checkHealth();
|
||||||
|
delay(3000);
|
||||||
|
|
||||||
|
if(roundCount > 4)
|
||||||
|
{
|
||||||
|
digitalWrite(PB2, HIGH);
|
||||||
|
while (1){}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
Reference in New Issue
Block a user