|
|
Ligne 14 : |
Ligne 14 : |
| ==fichiers à joindre== | | ==fichiers à joindre== |
| code, ficher d'impression 3D, de découpe laser ou vinyle, ... | | code, ficher d'impression 3D, de découpe laser ou vinyle, ... |
− | ===Code Arduino===
| |
− | <syntaxhighlight lang="Arduino" line>
| |
− | #include <Adafruit_NeoPixel.h>
| |
− |
| |
− | #define LED_STRIP_PIN 2
| |
− | #define NUM_LEDS 60
| |
− | #define BUZZER_PIN 3
| |
− |
| |
− | // Array to store the frequency of notes
| |
− | int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
| |
− |
| |
− | Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_STRIP_PIN, NEO_GRB + NEO_KHZ800);
| |
− |
| |
− | int lastButtonState[2] = {LOW}; // Array to store the previous state of each button
| |
− | unsigned long lastDebounceTime[2] = {0}; // Array to store the last debounce time of each button
| |
− | unsigned long buttonPressTime[2] = {0}; // Array to store the press time of each button
| |
− | unsigned long delayStart = 0; // Declaration of the global variable
| |
− | const int BTN[] = {6, 7};
| |
− | int x = 0;
| |
− | int y = 0;
| |
− |
| |
− | /*******************************************************************
| |
− | * @name :setup
| |
− | * @date :2024-01-30
| |
− | * @function :setup
| |
− | * @parameters :None
| |
− | * @retvalue :None
| |
− | ********************************************************************/
| |
− | void setup()
| |
− | {
| |
− | pinMode(BTN[0], INPUT);
| |
− | pinMode(BTN[1], INPUT);
| |
− | strip.begin();
| |
− | strip.show(); // Initialize all pixels to 'off'
| |
− | pinMode(BUZZER_PIN, OUTPUT);
| |
− | }
| |
− |
| |
− | /*******************************************************************
| |
− | * @name :loop
| |
− | * @date :2024-01-30
| |
− | * @function :loop
| |
− | * @parameters :None
| |
− | * @retvalue :None
| |
− | ********************************************************************/
| |
− | void loop()
| |
− | {
| |
− | // If there is a click
| |
− | if (click(0)) x++;
| |
− | if (click(1)) y++;
| |
− |
| |
− | // Set other pixels to 0
| |
− | for (int i = 0; i < NUM_LEDS; i++) strip.setPixelColor(i, 0);
| |
− |
| |
− | // Send pixels ON
| |
− | if (x == y)
| |
− | strip.setPixelColor(y, strip.Color(10, 0, 10));
| |
− | else
| |
− | {
| |
− | strip.setPixelColor(x, strip.Color(10, 0, 0));
| |
− | strip.setPixelColor(y, strip.Color(0, 0, 10));
| |
− | }
| |
− | strip.show();
| |
− |
| |
− | if (x == NUM_LEDS) {
| |
− | for (int i = NUM_LEDS; i >= 0; --i)
| |
− | {
| |
− | for (int j = 0; j < NUM_LEDS; j++) strip.setPixelColor(j, 0);
| |
− | strip.setPixelColor(i, strip.Color(10, 0, 0));
| |
− | strip.show();
| |
− | delay(10);
| |
− | }
| |
− | x = 0;
| |
− | y = 0;
| |
− | playMelody();
| |
− | }
| |
− |
| |
− | if (y == NUM_LEDS)
| |
− | {
| |
− | for (int i = NUM_LEDS; i >= 0; --i)
| |
− | {
| |
− | for (int j = 0; j < NUM_LEDS; j++) strip.setPixelColor(j, 0);
| |
− | strip.setPixelColor(i, strip.Color(0, 0, 10));
| |
− | strip.show();
| |
− | delay(10);
| |
− | }
| |
− | y = 0;
| |
− | x = 0;
| |
− | playMelody();
| |
− | delay(250);
| |
− | }
| |
− | }
| |
− |
| |
− | /*******************************************************************
| |
− | * @name :click
| |
− | * @date :2024-01-30
| |
− | * @function :click
| |
− | * @parameters :None
| |
− | * @retvalue :0 or 1
| |
− | ********************************************************************/
| |
− | bool click(int num)
| |
− | {
| |
− | int buttonState = digitalRead(BTN[num]);
| |
− |
| |
− | if (buttonState != lastButtonState[num])
| |
− | {
| |
− | lastDebounceTime[num] = millis();
| |
− |
| |
− | if (buttonState == HIGH)
| |
− | {
| |
− | lastButtonState[num] = buttonState;
| |
− | return true;
| |
− | }
| |
− | }
| |
− |
| |
− | lastButtonState[num] = buttonState;
| |
− | return false;
| |
− | }
| |
− |
| |
− |
| |
− | /*******************************************************************
| |
− | * @name :playMelody
| |
− | * @date :2024-01-30
| |
− | * @function :Do a victory melody
| |
− | * @parameters :None
| |
− | * @retvalue :None
| |
− | ********************************************************************/
| |
− | void playMelody() {
| |
− | // Iterate through all notes in the melody
| |
− | for (int i = 0; i < 8; i++)
| |
− | {
| |
− | // Play the note
| |
− | tone(BUZZER_PIN, notes[i], 200);
| |
− |
| |
− | // Wait for the duration of the note plus a short delay
| |
− | delay(200);
| |
− |
| |
− | // Stop the sound
| |
− | noTone(BUZZER_PIN);
| |
− |
| |
− | // Pause between notes
| |
− | delay(2);
| |
− | }
| |
− | }
| |
− |
| |
− | </syntaxhighlight>
| |
− |
| |
| ==étapes de fabrication== | | ==étapes de fabrication== |
| indiquer autant d'étape que nécessaire, chacune illustrée par des images (phot, dessins, ...) | | indiquer autant d'étape que nécessaire, chacune illustrée par des images (phot, dessins, ...) |