Skip to content

Commit

Permalink
Merge pull request #20 from PiFou86/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
aparent701 committed Dec 11, 2020
2 parents f424886 + 493dbe6 commit 9d118bc
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Module04_ProgrammationC/Module04_ProgrammationC.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Chaque bit du paramètre correspond à la position d'une DEL du montage qui doit
Au moment de la création d'une occurrence de la classe, le constructeur reçoit les numéros des 8 bornes branchées aux 8 DELs.
Avec TInkerCad, voici la structure de votre programme. Complétez le code.
Avec TinkerCad, voici la structure de votre programme. Complétez le code.
```cpp
// Début -- Affichage8DELs.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "Affichage8DELsGen.h"

class Affichage8DELs : public Affichage8DELsGen {
private:
int m_pinDELs[8];

public:
Affichage8DELs();
Affichage8DELs(int p_pinDel0);
Affichage8DELs(int p_pinDel0, int p_pinDel1);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5, int p_pinDel6);
Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5, int p_pinDel6, int p_pinDel7);

void Afficher(byte p_valeur) const;

static const int NONDEFINIES = -1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <Arduino.h>

class Affichage8DELsGen {

public:
// = 0 => Abstract ; const : la méthode ne modifit pas l'état de l'objet
virtual void Afficher(byte p_valeur) const = 0;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <Arduino.h>

#include "Affichage8DELsGen.h"

class Affichage8DELsRegistre : public Affichage8DELsGen {
private:
int m_pinDS;
int m_pinSH;
int m_pinST;

public:
Affichage8DELsRegistre(int p_pinDS, int p_pinSH, int p_pinST);
void Afficher(byte p_valeur) const;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "Affichage8DELsGen.h"

void GaucheDroite(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations = 1, const int &p_delai = 50);
void Compter(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations = 1, const int &p_delai = 25);
void K2000(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations = 1, const int &p_delai = 50);
39 changes: 39 additions & 0 deletions Module07_RegistreDecalage/DemoArduinoAffichage8DELs/include/README
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions Module07_RegistreDecalage/DemoArduinoAffichage8DELs/lib/README
Original file line number Diff line number Diff line change
@@ -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 a 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 changes: 15 additions & 0 deletions Module07_RegistreDecalage/DemoArduinoAffichage8DELs/platformio.ini
Original file line number Diff line number Diff line change
@@ -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:uno]
platform = atmelavr
board = uno
framework = arduino
build_flags = -I include
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "Affichage8DELs.h"

Affichage8DELs::Affichage8DELs()
: Affichage8DELs::Affichage8DELs(-1, -1, -1, -1, -1, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0)
: Affichage8DELs::Affichage8DELs(p_pinDel0, -1, -1, -1, -1, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, -1, -1, -1, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, p_pinDel2, -1, -1, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, p_pinDel2, p_pinDel3, -1, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, p_pinDel2, p_pinDel3, p_pinDel4, -1, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, p_pinDel2, p_pinDel3, p_pinDel4, p_pinDel5, -1, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5, int p_pinDel6)
: Affichage8DELs::Affichage8DELs(p_pinDel0, p_pinDel1, p_pinDel2, p_pinDel3, p_pinDel4, p_pinDel5, p_pinDel6, -1)
{
;
}

Affichage8DELs::Affichage8DELs(int p_pinDel0, int p_pinDel1, int p_pinDel2, int p_pinDel3,
int p_pinDel4, int p_pinDel5, int p_pinDel6, int p_pinDel7)
: m_pinDELs{
p_pinDel0, p_pinDel1, p_pinDel2, p_pinDel3,
p_pinDel4, p_pinDel5, p_pinDel6, p_pinDel7
}
{
for (int delIndex = 0; delIndex < 8; ++delIndex) {
if (this->m_pinDELs[delIndex] != Affichage8DELs::NONDEFINIES) {
pinMode(this->m_pinDELs[delIndex], OUTPUT);
}
}
}

void Affichage8DELs::Afficher(byte p_valeur) const {
byte valeurLed = 0;
for (int delIndex = 0; delIndex < 8; ++delIndex) {
if (this->m_pinDELs[delIndex] != Affichage8DELs::NONDEFINIES) {
valeurLed = (p_valeur >> delIndex) & 1;
digitalWrite(this->m_pinDELs[delIndex], valeurLed?HIGH:LOW);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Affichage8DELsRegistre.h"

Affichage8DELsRegistre::Affichage8DELsRegistre(int p_pinDS, int p_pinSH, int p_pinST)
: m_pinDS(p_pinDS), m_pinSH(p_pinSH), m_pinST(p_pinST)
{
// Si vous utilisez pas l'initialisaton après la parenthèse fermante :
// this.m_pinDS = p_pinDS;
// this.m_pinSH = p_pinSH;
// this.m_pinST = p_pinST;

pinMode(this->m_pinDS, OUTPUT);
pinMode(this->m_pinSH, OUTPUT);
pinMode(this->m_pinST, OUTPUT);
}


void Affichage8DELsRegistre::Afficher(byte p_valeur) const {
digitalWrite(this->m_pinST, LOW);

for (int i = 7; i >= 0; --i) {
digitalWrite(this->m_pinSH, LOW);
digitalWrite(this->m_pinDS, (p_valeur >> i) & 1);
digitalWrite(this->m_pinSH, HIGH);
}

digitalWrite(this->m_pinST, HIGH);
digitalWrite(this->m_pinST, LOW);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Animations.h"

void GaucheDroite(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations, const int &p_delai) {
for (int iterationCourante = 0; iterationCourante < p_nombreIterations; ++iterationCourante) {
for (int indiceLed = 0; indiceLed < 8; ++indiceLed) {
p_afficheur.Afficher(1 << indiceLed);
delay(p_delai);
}

for (int indiceLed = 0; indiceLed < 8; ++indiceLed) {
p_afficheur.Afficher(0x80 >> indiceLed);
delay(p_delai);
}
}
}

void Compter(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations, const int &p_delai) {
for (int iterationCourante = 0; iterationCourante < p_nombreIterations; ++iterationCourante) {
for (int valeur = 0; valeur < 256; ++valeur) {
p_afficheur.Afficher(valeur);
delay(p_delai);
}
}
}

void K2000(const Affichage8DELsGen &p_afficheur, const int &p_nombreIterations, const int &p_delai) {
for (int iterationCourante = 0; iterationCourante < p_nombreIterations; ++iterationCourante) {
for (int indiceLed = 0; indiceLed < 8; ++indiceLed) {
p_afficheur.Afficher(0xE0 >> indiceLed);
delay(p_delai);
}

for (int indiceLed = 0; indiceLed < 8; ++indiceLed) {
p_afficheur.Afficher(7 << indiceLed);
delay(p_delai);
}
delay(p_delai * 6);
}
}
25 changes: 25 additions & 0 deletions Module07_RegistreDecalage/DemoArduinoAffichage8DELs/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <Arduino.h>

#include "Affichage8DELsRegistre.h"
#include "Affichage8DELs.h"
#include "Animations.h"

const int pinST = 11;
const int pinSH = 8;
const int pinDS = 12;

Affichage8DELsRegistre a8DELs(pinDS, pinSH, pinST);
//Affichage8DELs a8DELs(2, 3, 4, 5, 6, 7, 8, 9);
void setup()
{
;
}

void loop()
{
Compter(a8DELs);

GaucheDroite(a8DELs, 10);

K2000(a8DELs, 10);
}
11 changes: 11 additions & 0 deletions Module07_RegistreDecalage/DemoArduinoAffichage8DELs/test/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

This directory is intended for PlatformIO Unit Testing 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/page/plus/unit-testing.html

0 comments on commit 9d118bc

Please sign in to comment.