Create proton_pack_state_machine.ino

Create proton_pack_state_machine.ino

This is an implementation of the Proton pack effects using a state machine and an Adafruit sound board.

/* Proton pack lights sounds v2.0 (2021-10-13)

This code drives two sets of two 74HC595N shift registers. One set controls the 'power cell' LEDs
of the proton pack, the other set runs the 'bargraph' and two firing LEDs on the thrower/wand.
My pack's cyclotron lights are controlled by a 4017 decade counter and 555 timer however one could
use the remaining available pins of the arduino to control the cyclotron.
Please note with this code that I'm not going for total screen accuracy, simply something that
looks pretty close. However, the patterns should be fairly easy to understand and modify if you
wish to produce something very authentic to that seen on screen (or even in the video game).
Feel free to use the code in your own project, the only thing I ask is that you share any
modifications, ideally also on gbfans.com forums.

For an excellent overview of using shift registers with arduino please see this video:
https://www.youtube.com/watch?v=Ys2fu4NINrA

 Martinux
*/

// ===============================================================================================
// ADAFRUIT AUDIO FX BOARD
// ===============================================================================================
// UG to Ground
// TX to #5
// RX to #6
// RST to #4
// ACT to #3
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

#define SFX_TX 5
#define SFX_RX 6
#define SFX_RST 4  // Reset
#define ACT 3
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

// audio track names on soundboard
char power_on_snd[] =     "T00     WAV";
char firing_snd[] =       "T01     WAV";
char stop_firing_snd[] =  "T02     WAV";
char hum_long_snd[] =     "T03     WAV";
char hum_snd[] =          "T03_SH~1WAV";
char power_down_snd[] =   "T04     WAV";
char clickTrack[] =       "T05     WAV";
char charge_snd[] =       "T06     WAV";
char overheat_snd[] =     "T07     WAV";
char vent_snd[] =         "T08     WAV";
char texTrack[] =         "T09     WAV";
char choreTrack[] =       "T10     WAV";
char toolsTrack[] =       "T11     WAV";
char listenTrack[] =      "T12     WAV";
char thatTrack[] =        "T13     WAV";
char neutronizedTrack[] = "T14     WAV";
char boxTrack[] =         "T15     WAV";
char slowTheme[] =        "T16     OGG";

int audio_playing;  // to keep track if a sound is playing.

// ===============================================================================================
// STATE MACHINE PHASE TRACKING
// ===============================================================================================
int current_pack_state = 0;
int previous_pack_state = 0;
int first_power_up = 1;

// ===============================================================================================
// TIMEKEEPING
// ===============================================================================================
unsigned long currentMillis = 0;
unsigned long previousMillis_on = 0;
unsigned long previousMillis_fire = 0;
unsigned long off_interval = 30;
unsigned long pwrcl_interval = 70;     // interval at which to cycle lights (milliseconds).
unsigned long max_firing_interval = 60;
unsigned long min_firing_interval = 40;
unsigned long firing_interval = max_firing_interval;    // interval at which to cycle firing lights (milliseconds).
unsigned long overheat_interval = 200;
int max_wand_overheat_cycles = overheat_interval / min_firing_interval;
int wand_overheat_cycles;

// ===============================================================================================
// BUTTONS
// ===============================================================================================
#define DEBOUNCE 5  // button debouncing.
// Pins 14, 15 and 16 are Analog 0, 1 and 2 respectively.
int power_button = 14;
int firing_button = 15;
int aux_button = 16;  // Currently held in reserve for use with Adafruit audio shield.
int power_button_state;
int firing_button_state;
int aux_button_state;

// ===============================================================================================
// SHIFT REGISTERS
// ===============================================================================================
int clockPinPWR = 7;  // Power cell
int dataPinPWR = 8;  // Power cell
int latchPin = 9;
int clockPinWand = 18;  // (18 is analog pin 4 on arduino)
int dataPinWand = 19;   // (19 is analog pin 5 on arduino)

// data array position trackers
int power_cell_array_pos = 0;
int wand_array_pos = 0;
int wand_active_array_pos = 0;
int overheat_array_pos = 0;
// holders for information we're going to pass to shifting function
byte dataPwrCell;
byte dataWand;
byte dataWandON;

// ===============================================================================================
// Populate light pattern arrays into flash memory to save RAM
// ===============================================================================================
// power cell LEDs 0 through 7 then LEDs 8 through 15 (two shift registers)
const PROGMEM uint16_t PwrCell[] = {B10000000,B00000000,
                                    B11000000,B00000000,
                                    B11100000,B00000000,
                                    B11110000,B00000000,
                                    B11111000,B00000000,
                                    B11111100,B00000000,
                                    B11111110,B00000000,
                                    B11111111,B00000000,
                                    B11111111,B10000000,
                                    B11111111,B11000000,
                                    B11111111,B11100000,
                                    B11111111,B11110000,
                                    B11111111,B11111000,
                                    B11111111,B11111100,
                                    B11111111,B11111110
                                    };

//Proton Wand idle pattern - two shift registers
const PROGMEM uint16_t Wand[] = {B01000000,B00000000,
                                 B01100000,B00000000,
                                 B01110000,B00000000,
                                 B01111000,B00000000,
                                 B01111100,B00000000,
                                 B01111110,B00000000,
                                 B01111111,B10000000,
                                 B01111111,B11000000,
                                 B01111111,B11100000,
                                 B01111111,B11110000,
                                 B01111111,B11111000,
                                 B01111111,B11111100,
                                 B01111111,B11111110,
                                 B01111111,B11111100,
                                 B01111111,B11111000,
                                 B01111111,B11110000,
                                 B01111111,B11100000,
                                 B01111111,B11000000,
                                 B01111111,B10000000,
                                 B01111111,B00000000,
                                 B01111110,B00000000,
                                 B01111100,B00000000,
                                 B01111000,B00000000,
                                 B01110000,B00000000,
                                 B01100000,B00000000,
                                 B01000000,B00000000
                                 };

// Proton Wand firing pattern - two shift registers
// 10000000 and 00000001 used for Wand barrel strobe
const PROGMEM uint16_t WandON[] = {B11000000,B00000010,
                                   B00100000,B00000101,
                                   B10010000,B00001000,
                                   B00001000,B00010001,
                                   B10000100,B00100000,
                                   B00000010,B01000001,
                                   B10000001,B10000000,
                                   B10000001,B10000000,
                                   B10000001,B10000000,
                                   B00000010,B01000001,
                                   B10000100,B00100000,
                                   B00001000,B00010001,
                                   B10010000,B00001000,
                                   B00100000,B00000101,
                                   B11000000,B00000010
                                   };

// Overheat patterns
const PROGMEM uint16_t OHWand1[] = {B00000000,
                                    B01000000,
                                    B01100000,
                                    B01110000,
                                    B01111000,
                                    B01111100,
                                    B01111110,
                                    B01111111,
                                    B01111111,
                                    B01111111,
                                    B01111111,
                                    B01111111,
                                    B01111111,
                                    B01111111
                                    };
const PROGMEM uint16_t OHWand2[] = {B00000000,
                                    B00000000,
                                    B00000000,
                                    B00000000,
                                    B00000000,
                                    B00000000,
                                    B00000000,
                                    B00000000,
                                    B10000000,
                                    B11000000,
                                    B11100000,
                                    B11110000,
                                    B11111000,
                                    B11111100
                                    };
const PROGMEM uint16_t OHPwrCell[] = {B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110,
                                      B00000000,B00000000,
                                      B01111111,B11111110
                                      };

int freeRam(void) {
    extern int  __bss_end;
    extern int  *__brkval;
    int free_memory;
    if((int)__brkval == 0) {
        free_memory = ((int)&free_memory) - ((int)&__bss_end);
    }
    else {
        free_memory = ((int)&free_memory) - ((int)__brkval);
    }
    return free_memory;
}

void setup() {
    // set up serial port
    //Serial.begin(9600);
    Serial.begin(115200);
    while (!Serial);  // wait for serial port to connect. Needed for native USB

    Serial.print(F("Free RAM: "));
    Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!

    // Make input & enable pull-up resistors on switch pins
    pinMode(power_button, INPUT_PULLUP);
    pinMode(firing_button, INPUT_PULLUP);
    pinMode(aux_button, INPUT_PULLUP);

    // Set pins for shift registers:
    pinMode(latchPin, OUTPUT);      // shared between power cell and thrower
    pinMode(clockPinPWR, OUTPUT);
    pinMode(clockPinWand, OUTPUT);
    pinMode(dataPinPWR, OUTPUT);
    pinMode(dataPinWand, OUTPUT);
    // Initialise Power cell and Wand lights
    initialise_lights();

    // softwareserial at 9600 baud
    ss.begin(9600);
    // can also do Serial1.begin(9600)

    if (!sfx.reset()) {
    Serial.println("Not found");
        while (1);
    }
    Serial.println("SFX board found");
    uint8_t files = sfx.listFiles();

    Serial.println("File Listing");
    Serial.println("========================");
    Serial.println();
    Serial.print("Found "); Serial.print(files); Serial.println(" Files");
    for (uint8_t f = 0; f < files; f++) {
        Serial.print(f);
        Serial.print("\tname: "); Serial.print(sfx.fileName(f));
        Serial.print("\tsize: "); Serial.println(sfx.fileSize(f));
    }
    Serial.println("========================");
}

void loop() {
    audio_playing = digitalRead(ACT);  // False if audio playing.
    pack_state();  // all the "magic" is done in this function
    if (previous_pack_state != current_pack_state) {
        Serial.print(F("STATE: "));
        Serial.println(current_pack_state);
    }
}

// ===============================================================================================
// State machine
// ===============================================================================================
void pack_state() {
    previous_pack_state = current_pack_state;
    switch (current_pack_state) {
        case 0:  // Pack default state & reset variables
            //overheat_array_pos = 0;
            firing_interval = max_firing_interval;
            wand_overheat_cycles = max_wand_overheat_cycles;
            current_pack_state = 1;  // next cycle move onto Start state
            break;

        case 1:  // Start
            power_button_state = digitalRead(power_button);
            if (power_button_state == LOW) {  // power switch pressed.
                if (first_power_up) {
                    playAudio(power_on_snd, audio_playing);
                    Serial.println(F("First power on of pack."));
                    first_power_up = 0;
                }
                else {
                    current_pack_state = 2;
                }
            }
            break;

        case 2: // Powered on
            power_button_state = digitalRead(power_button);
            firing_button_state = digitalRead(firing_button);
            // After playing power up play pack hum on loop:
            if ( (power_button_state == LOW) && (audio_playing == 1) ) {
                 playAudio(hum_snd, audio_playing);
            }
            if (power_button_state == HIGH) {
                playAudio(power_down_snd, audio_playing);
                first_power_up = 1;
                current_pack_state = 3;  // Next cycle power down.
            }
            if (firing_button_state == LOW) {
                playAudio(firing_snd, audio_playing);
                current_pack_state = 4;  // Next cycle run firing routine.
            }
            powered_on();
            break;

        case 3: // Power down
            powered_down();
            break;

        case 4: // Firing
            power_button_state = digitalRead(power_button);
            firing_button_state = digitalRead(firing_button);
            if ((power_button_state == HIGH) && (firing_button_state == LOW)) {
                current_pack_state = 3;
            }
            if (firing_button_state == HIGH) {
                playAudio(stop_firing_snd, audio_playing);
                current_pack_state = 5;
            }
            firing();
            break;

        case 5: // End firing
            current_pack_state = 2;
            break;

        case 6: // Overheat
            power_button_state = digitalRead(power_button);
            firing_button_state = digitalRead(firing_button);
            if (firing_button_state == HIGH) {
                playAudio(stop_firing_snd, audio_playing);
                overheat_array_pos = 0;
                current_pack_state = 2;
            }
            overheat();
            break;

        case 7: // Overheat lockout (pack shuts down until vented)
            firing_button_state = digitalRead(firing_button);
            if (firing_button_state == HIGH) {
                playAudio(vent_snd, audio_playing);
                if (audio_playing == 1) {
                     current_pack_state = 0;
                }
            }
            break;

    }
}

// ===============================================================================================
// Pack states
// ===============================================================================================
void initialise_lights() {
    digitalWrite(latchPin, 0);
    shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, B11000000);  // First 8 LEDs
    shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, B00000000);  // Second 8 LEDs
    shiftOut(dataPinWand, clockPinWand, MSBFIRST, B01000000);
    shiftOut(dataPinWand, clockPinWand, MSBFIRST, B00000000);
    digitalWrite(latchPin, 1);
}

void powered_on() {
    currentMillis = millis();
    if (currentMillis - previousMillis_on > pwrcl_interval) {
        previousMillis_on = currentMillis;
        digitalWrite(latchPin, 0);  // Low to send data

        // Load the light sequence from arrays then send data to shift registers:
        dataPwrCell = pgm_read_word_near(PwrCell + power_cell_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);
        power_cell_array_pos++;
        dataPwrCell = pgm_read_word_near(PwrCell + power_cell_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);

        dataWand = pgm_read_word_near(Wand + wand_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);
        wand_array_pos++;
        dataWand = pgm_read_word_near(Wand + wand_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);

        digitalWrite(latchPin, 1);  // high to make shift register output data.

        power_cell_array_pos++;
        if (power_cell_array_pos > 29) {
             power_cell_array_pos = 0;
        }
        wand_array_pos++;
        if (wand_array_pos > 49) {
            wand_array_pos = 0;
        }
    }
}

void powered_down() {
    currentMillis = millis();
    if (currentMillis - previousMillis_on > off_interval) {
        previousMillis_on = currentMillis;
        if (wand_array_pos != power_cell_array_pos) {
            wand_array_pos = power_cell_array_pos;
        }

        digitalWrite(latchPin, 0);  // Low to send data
        // Load the light sequence from arrays then send data to shift registers:
        dataPwrCell = pgm_read_word_near(PwrCell + power_cell_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);
        dataPwrCell = pgm_read_word_near(PwrCell + (power_cell_array_pos + 1));
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);

        dataWand = pgm_read_word_near(Wand + wand_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);
        dataWand = pgm_read_word_near(Wand + (wand_array_pos + 1));
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);
        digitalWrite(latchPin, 1);  // high to make shift register show data.

        power_cell_array_pos -= 2;
        if (power_cell_array_pos < 0) {
            power_cell_array_pos = 0;
            current_pack_state = 0;
        }
        wand_array_pos -= 2;
        if (wand_array_pos < 0) {
            wand_array_pos = 0;
            current_pack_state = 0;
        }
    }
}

void firing() {
    currentMillis = millis();
    if (currentMillis - previousMillis_on > firing_interval) {
        previousMillis_on = currentMillis;
        digitalWrite(latchPin, 0);  // Low to send data

        dataPwrCell = pgm_read_word_near(PwrCell + power_cell_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);
        power_cell_array_pos++;
        dataPwrCell = pgm_read_word_near(PwrCell + power_cell_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);

        dataWandON = pgm_read_word_near(WandON + wand_active_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWandON);
        wand_active_array_pos++;
        dataWandON = pgm_read_word_near(WandON + wand_active_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWandON);

        digitalWrite(latchPin, 1);  // high to make shift register show data.

        power_cell_array_pos++;
        if (power_cell_array_pos > 28) {
            firing_interval--;
            Serial.print(F("Firing interval: "));
            Serial.println(firing_interval);
            power_cell_array_pos = 0;
        }
        wand_active_array_pos++;
        if (wand_active_array_pos > 28) {
            wand_active_array_pos = 0;
        }
        if (firing_interval == min_firing_interval) {
            playAudio(overheat_snd, audio_playing);
            wand_active_array_pos = 0;
            current_pack_state = 6;
        }
    }
}

void overheat() {
    currentMillis = millis();
    if (currentMillis - previousMillis_fire > firing_interval) {
        previousMillis_fire = currentMillis;
        digitalWrite(latchPin, 0);  // Low to send data

        dataWandON = pgm_read_word_near(WandON + wand_active_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWandON);
        wand_active_array_pos++;
        dataWandON = pgm_read_word_near(WandON + wand_active_array_pos);
        shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWandON);

        digitalWrite(latchPin, 1);  // high to make shift register show data.

        wand_active_array_pos++;
        if (wand_active_array_pos > 28) {
            wand_active_array_pos = 0;
        }
    }
    if (currentMillis - previousMillis_on > overheat_interval) {
        previousMillis_on = currentMillis;
        /*
        // 5x wand cycles for every powercell cycle
        for (wand_overheat_cycles = 0; wand_overheat_cycles < max_wand_overheat_cycles; wand_overheat_cycles++) {
            Serial.print("wand_overheat_cycles: ");
            Serial.println(wand_overheat_cycles);
            digitalWrite(latchPin, 0);  // Low to send data

            dataWand = pgm_read_word_near(OHWand1 + wand_active_array_pos);
            Serial.print(dataWand, BIN);
            Serial.print(F("|"));
            if (wand_overheat_cycles % 2 == 0) { // flip the strobe every other cycle
                dataWand ^= 1 << 7;  // Red firing LED
            }
            Serial.print(dataWand, BIN);
            shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);

            Serial.print(F(" || "));

            dataWand = pgm_read_word_near(OHWand2 + wand_active_array_pos);
            Serial.print(dataWand, BIN);
            Serial.print(F("|"));
            if (wand_overheat_cycles % 2 == 1) { // flip the strobe every other cycle
                dataWand ^= 1 << 0;  // Blue firing LED
            }
            Serial.println(dataWand, BIN);
            shiftOut(dataPinWand, clockPinWand, MSBFIRST, dataWand);

            digitalWrite(latchPin, 1);  // high to make shift register show data.
        }
        wand_active_array_pos++;
        Serial.print(F("wand_active_array_pos: "));
        Serial.println(wand_active_array_pos);
        if (wand_active_array_pos > 28) {
            wand_active_array_pos = 0;
        }
        */

        digitalWrite(latchPin, 0);  // Low to send data

        // Load the light sequence from arrays then send data to shift registers:
        dataPwrCell = pgm_read_word_near(OHPwrCell + overheat_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);
        overheat_array_pos++;
        dataPwrCell = pgm_read_word_near(OHPwrCell + overheat_array_pos);
        shiftOut(dataPinPWR, clockPinPWR, MSBFIRST, dataPwrCell);

        digitalWrite(latchPin, 1);  // high to make shift register show data.

        overheat_array_pos++;
        if (overheat_array_pos > 26) {
            Serial.println(F("Finished overheat cycle."));
            overheat_array_pos = 0;
            playAudio(stop_firing_snd, audio_playing);
            initialise_lights();
            current_pack_state = 7;
        }
    }
}

void playAudio( char* trackname, int audio_playing ) {
  // stop track if one is going
  if (audio_playing == 0) {
    sfx.stop();
  }

  // now go play
  if (sfx.playTrack(trackname)) {
    sfx.unpause();
  }
}

error: pathspec 'proton_pack_state_machine.ino' did not match any file(s) known to git


Actulizo fichero de config

Actulizo fichero de config

error: pathspec '01-persiana/sketch/config' did not match any file(s) known to git
error: pathspec 'sample.ino' did not match any file(s) known to git


Added RGB light to sketches folder

Added RGB light to sketches folder

error: pathspec 'Home' did not match any file(s) known to git
error: pathspec 'Automation/Sketches/RGBLight/RGBLight.ino' did not match any file(s) known to git


Add Feather M0 WiFi example

Add Feather M0 WiFi example

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example shows how to use Adafruit Feather M0 WiFi
 * to connect your project to Blynk.
 *
 * Note: This requires WiFi101 library
 *   from http://librarymanager/all#WiFi101
 *
 * Feel free to apply it to any other example. It's simple!
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  Serial.begin(9600);

  WiFi.setPins(8,7,4,2);

  Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, server_ip, port);
}

void loop()
{
  Blynk.run();
}

error: pathspec 'examples/Boards_WiFi/Adafruit_Feather_M0_WiFi/Adafruit_Feather_M0_WiFi.ino' did not match any file(s) known to git


Start work on RFID source

Start work on RFID source

/*
   IoT Dataflow Graph Server
   Copyright (c) 2015, Adam Rehn, Jason Holdsworth
                 2018, Wilson Bow

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

/*
 * Great tutorial (most of code copied from here): https://www.brainy-bits.com/card-reader-with-an-arduino-rfid-using-the-rc522-module/
 * Note that SDA pin in this site is actually NSS on our device
 *
 * The MRFC522 library to be used can be found at: https://github.com/ljos/MFRC522
 * This one has been forked and updated from the MRFC522 library from the Library Manager!
 */

#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <ESP8266MulticastUDP.h>
#include <SPI.h>
#include <MFRC522.h>

//The identifier for this node
const String& NODE_IDENTIFIER = "light-source";

//The interval (in milliseconds) at which input is read
#define READ_INTERVAL 100

// Setup the ESP8266 Multicast UDP object as a source
ESP8266MulticastUDP multicast("iot-dataflow", "it-at-jcu",
  IPAddress(224, 0, 0, 114), 7070);

#define ERROR_PIN 15
#define NSSPIN 13
#define RESETPIN 12
#define MAX_LEN 5

byte FoundTag;
byte ReadTag;
byte TagData[MAX_LEN];
byte TagSerialNumber[5];
byte GoodTagSerialNumber[5] = {0x71, 0xB4, 0x21, 0x32};

MFRC522 nfc(NSSPIN, RESETPIN);

void setup()
{
  //Initialise serial communications
  SPI.begin();
  Serial.begin(115200);
  nfc.begin();
  byte version = nfc.getFirmwareVersion();
  if(!version){
    Serial.print("Didn't find RC522 board");
    while(1);
  }

  multicast.begin();
  Serial.print(NODE_IDENTIFIER);
  if (multicast.isConnected()) {
    Serial.println(" connected to Wifi network");
  } else {
    Serial.println(" error: failed to connect to WiFi network!");
    pinMode(ERROR_PIN, OUTPUT);
    digitalWrite(ERROR_PIN, HIGH);
  }
}

//Reads the current sensor input
// Note: a light sensor returns a value 0 (bright light) - 1023 (darkness)
// so we adjust the range to be 0 - 100
int readSource() {
  String GoodTag = "False";
  FoundTag = nfc.requestTag(MF1_REQIDL, TagData);

  if (FoundTag == MI_OK){
    delay(200);

    ReadTag = nfc.antiCollision(TagData);
    memcpy(TagSerialNumber, TagData, 4);
    Serial.println("Tag detected.");
    Serial.print("Serial Number: ");
    for (int i = 0; i < 4; i++){
      Serial.print(TagSerialNumber[i], HEX);
      Serial.print(", ");
    }
    Serial.println("");
    Serial.println();
  }

  for(int i = 0; i < 4; i++){
    if(GoodTagSerialNumber[i] != TagSerialNumber[i]){
      break;
    }
    if (i == 3){
      GoodTag = "True";
    }
  }
  if (GoodTag == "True"){
    Serial.println("Success!");
    return 1;
  } else {
    Serial.println("Tag not accepted :(");
    return 0;
  }
}

void loop()
{
  if (multicast.isConnected())
  {
    String message = String(NODE_IDENTIFIER) + "\n" + readSource();
    multicast.write(message);
    delay(READ_INTERVAL);
  }
}

error: pathspec 'real-devices/Arduino/ESP8266/sources/rfid-source/rfid-source.ino' did not match any file(s) known to git


New Arduino code added

New Arduino code added

#include <LiquidCrystal.h>
#include <OneSheeld.h>
#include <GPSShield.h>
#include <SMSShield.h>
LiquidCrystal lcd(6, 7, 10, 11, 12, 13);
int buttonState = 0;
boolean isMessageSent = false;
float get_latitude ;
float get_longitude ;
String latitude ;
String longitude ;
String sms_text ;
float volt_2_gl(float v){
  float a = 2.64581 ;
  float b = 0.59843 ;
  float gl = (v-a)/b ;
  return gl ;
}
void setup() {
  OneSheeld.begin(); // Start communication with 1Sheeld
  lcd.begin(1, 2);
  pinMode(9, INPUT);
  pinMode(4, OUTPUT);
  lcd.print("P. Pennestri'");
  lcd.setCursor(0, 1);
  lcd.print("L.S.S. I. Newton");
  delay(3000);
  lcd.clear();
  lcd.print("Warming Up");
  lcd.setCursor(0, 1);
  lcd.print("Don't Breath");
  delay(30000);
  lcd.clear();
}

void loop() {
   buttonState = digitalRead(9); // read the state of the pushbutton value
   if (buttonState == HIGH) {
   isMessageSent = false;
   lcd.print("Breath in");
   delay(15000);
   delay(15000);
   delay(15000);
   delay(5000);
   lcd.clear();
   digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);              // wait for a second
   digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);              // wait for a second
   int mq3_value1 = analogRead(A5);
   float voltage1 = mq3_value1 * (5.0 / 1023.0); // get mq3 voltage

   if(voltage1<2.42){
    lcd.print("No alcohol");
    lcd.setCursor(0, 1);
    lcd.print("You can drive ");
    delay(15000);
    lcd.clear();
   }

   if(voltage1>=2.42){
     float response = volt_2_gl(voltage1);
     // send sms if response >= 0.5 g/l
     lcd.print(response);
     lcd.print(" g/l");
     lcd.setCursor(0, 1);
     lcd.print("DO NOT DRIVE!");
     delay(15000);
     delay(15000);
     delay(15000);
     delay(5000);
     lcd.clear();

          if(response>=0.5){

        if(!isMessageSent)
    {
         lcd.print("SMS Sent");
         lcd.clear();
         get_latitude = GPS.getLatitude();
         latitude = String(get_latitude);
         get_longitude = GPS.getLongitude();
         longitude = String(get_longitude);
         sms_text = "I need HELP \n pick me up at \n https://www.google.it/maps/place/" + latitude + "+" + longitude  ;

         SMS.send("3511012085", sms_text);  // send sms
         isMessageSent = true;  // Set the flag.
        delay(10000);
    }

     }

     lcd.print("Going to idle state");
     lcd.setCursor(0, 1);
     lcd.print("Don't Breath");
     delay(15000);
     delay(15000);
     delay(15000);
     delay(5000);
   }} else{
     lcd.print("Ready to Start");
     delay(1000);
     lcd.clear();
   }

}

error: pathspec 'arduino/mq3_shield/mq3_shield_4_newton.ino' did not match any file(s) known to git


replace approximation table size by macro

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/dave-ausbone/TJU-SST.git/'


Add I2C interface to external mouse device

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mvines/futboard.git/'


Add scroll wheel message

Add scroll wheel message


Adding test of optimization strategy for switch statements.

/**
 * @file CosaSwitch.ino
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2014, Mikael Patel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * @section Description
 * Testing code generation of switch statements.
 *
 * This file is part of the Arduino Che Cosa project.
 */

#include "Cosa/RTC.hh"
#include "Cosa/Watchdog.hh"
#include "Cosa/Trace.hh"
#include "Cosa/IOStream/Driver/UART.hh"

enum {
  OP_ADD,
  OP_SUB,
  OP_MUL,
  OP_DIV,
  OP_REM,
  OP_LOAD,
  OP_STORE,
  OP_BRA,
  OP_BRZ,
  OP_CALL,
  OP_EXIT
};

// Traditional switch statement will compile to if-else if
#define DISPATCH(op) switch (op)
#define OP(x) case OP_ ## x:
int switch_fn(uint8_t op)
{
  int res = 0;
  DISPATCH(op) {
    OP(ADD)
      res = 1;
    break;
    OP(SUB)
      res = 2;
    break;
    OP(MUL)
      res = 3;
    break;
    OP(DIV)
      res = 4;
    break;
    OP(REM)
      res = 5;
    break;
    OP(LOAD)
      res = 6;
    break;
    OP(STORE)
      res = 7;
    break;
    OP(BRA)
      res = 8;
    break;
    OP(BRZ)
      res = 9;
    break;
    OP(CALL)
      res = 10;
    break;
    OP(EXIT)
      res = 11;
    break;
  }
  return (res);
}
#undef OP
#undef DISPATCH

// Table driven switch statement using gcc goto extension and program memory table
#define OP(x) DO_ ## x:
#define DISPATCH(op) goto *pgm_read_word(&tab[op]); for (uint8_t i = 0; i < 1; i++)
int goto_fn(uint8_t op)
{
  // Label address table
  static const void* tab[] __PROGMEM = {
    &&DO_ADD,
    &&DO_SUB,
    &&DO_MUL,
    &&DO_DIV,
    &&DO_REM,
    &&DO_LOAD,
    &&DO_STORE,
    &&DO_BRA,
    &&DO_BRZ,
    &&DO_CALL,
    &&DO_EXIT
  };
  int res = 0;

  // Switch implementation with table and do-while(0) loop to allow break
  DISPATCH(op) {
    OP(ADD)
      res = 1;
    break;
    OP(SUB)
      res = 2;
    break;
    OP(MUL)
      res = 3;
    break;
    OP(DIV)
      res = 4;
    break;
    OP(REM)
      res = 5;
    break;
    OP(LOAD)
      res = 6;
    break;
    OP(STORE)
      res = 7;
    break;
    OP(BRA)
      res = 8;
    break;
    OP(BRZ)
      res = 9;
    break;
    OP(CALL)
      res = 10;
    break;
    OP(EXIT)
      res = 11;
    break;
  }
  return (res);
}

void setup()
{
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaGoto: started"));
  Watchdog::begin();
  RTC::begin();
}

void loop()
{
  uint32_t start, stop, us;
  uint8_t* switch_fn_addr = (uint8_t*) switch_fn;
  uint8_t* goto_fn_addr = (uint8_t*) goto_fn;
  uint8_t* loop_addr = (uint8_t*) loop;
  size_t switch_fn_size = goto_fn_addr - switch_fn_addr;
  size_t goto_fn_size = loop_addr - goto_fn_addr;
  int res;

  // Measure traditional switch statement version
  TRACE(switch_fn_addr);
  TRACE(switch_fn_size);
  for (uint8_t op = OP_ADD; op <= OP_EXIT; op++)
    TRACE(switch_fn(op));
  start = RTC::micros();
  res = 0;
  for (int i = 0; i < 1000; i++)
    for (uint8_t op = OP_ADD; op <= OP_EXIT; op++)
      res += switch_fn(op);
  stop = RTC::micros();
  us = stop - start;
  TRACE(res);
  TRACE(us);
  start = RTC::micros();
  for (int i = 0; i < 10000; i++)
    for (uint8_t op = OP_LOAD; op <= OP_EXIT; op++)
      res += switch_fn(op);
  stop = RTC::micros();
  us = stop - start;
  TRACE(res);
  TRACE(us);

  // Measure goto-label table version
  TRACE(goto_fn_addr);
  TRACE(goto_fn_size);
  for (uint8_t op = OP_ADD; op <= OP_EXIT; op++)
    TRACE(goto_fn(op));
  start = RTC::micros();
  res = 0;
  for (int i = 0; i < 1000; i++)
    for (uint8_t op = OP_ADD; op <= OP_EXIT; op++)
      res += goto_fn(op);
  stop = RTC::micros();
  us = stop - start;
  TRACE(res);
  TRACE(us);
  start = RTC::micros();
  for (int i = 0; i < 10000; i++)
    for (uint8_t op = OP_LOAD; op <= OP_EXIT; op++)
      res += goto_fn(op);
  stop = RTC::micros();
  us = stop - start;
  TRACE(res);
  TRACE(us);

  ASSERT(true == false);
}

error: pathspec 'examples/Sandbox/CosaSwitch/CosaSwitch.ino' did not match any file(s) known to git


the c++ status bot with RGB lcd display is finally coming together

#include "application.h"
#include "LiquidCrystal/LiquidCrystal.h"

// Colors
#define RGB_COLOR_RED   0xFF0000ul
#define RGB_COLOR_GREEN   0x00FF00ul
#define RGB_COLOR_BLUE    0x0000FFul
#define RGB_COLOR_YELLOW  0xFFFF00ul
#define RGB_COLOR_CYAN    0x00FFFFul
#define RGB_COLOR_MAGENTA 0xFF00FFul
#define RGB_COLOR_WHITE   0xFFFFFFul
#define RGB_COLOR_ORANGE    0xFF6000ul
#define WIZARD_ORANGE       0xc03f21ul
#define WIZARD_BLUE         0x285166ul
#define WIZARD_GRAY         0x515159ul

// Pins for backlight
#define R_PIN D0
#define G_PIN A0
#define B_PIN A1

// Make sure to update these to match how you've wired your pins.
// pinout on LCD [RS, EN, D4, D5, D6, D7];
LiquidCrystal lcd(A2, A3, D3, D4, D5, D6);

int brightness = 255;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16,2);

  // Setup pinmodes
  pinMode(R_PIN, OUTPUT);
  pinMode(G_PIN, OUTPUT);
  pinMode(B_PIN, OUTPUT);

  backlight(WIZARD_ORANGE);
    lcd.print("Wizard Dev");
  lcd.setCursor(0,1);
  lcd.print("Hello Programs!");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("StatusBot Online");

  Spark.function("backlight", netBacklight);
  Spark.function("testBacklight", testBacklight);
  Spark.function("printLCD", printLCD);
}

void loop() {

}

int printLCD (String message) {
  lcd.clear();
  lcd.print(message);
  return 1;
}

int netBacklight(String args) {
  char color[7]; // six hex and null
  args.toCharArray(color, sizeof(color));
  backlight(strtoul(color,0, 16));
  return 1;
}

int testBacklight(String args) {
  backlight(RGB_COLOR_RED);
  delay(1000);
  backlight(RGB_COLOR_GREEN);
  delay(1000);
  backlight(RGB_COLOR_BLUE);
  delay(1000);
  backlight(WIZARD_ORANGE);
  delay(1000);
  backlight(WIZARD_BLUE);
  delay(1000);
  backlight(WIZARD_GRAY);
  delay(1000);
  return 1;
}

void backlight(unsigned long rgb) {
  // lcd.clear();

  int r = rgb >> 16 & 0x0000FF;
  int g = rgb >> 8 & 0x0000FF;
  int b = rgb & 0x0000FF;

  // lcd.print("RGB #");
  // lcd.print(r, HEX);
  // lcd.print(g, HEX);
  // lcd.print(b, HEX);

  // normalize the red and green LEDs - they are brighter than the rest!
  r = map(r, 0, 255, 0, 100);
  g = map(g, 0, 255, 0, 150);

  r = map(r, 0, 255, 0, brightness);
  g = map(g, 0, 255, 0, brightness);
  b = map(b, 0, 255, 0, brightness);

  // common anode so invert!
  r = map(r, 0, 255, 255, 0);
  g = map(g, 0, 255, 255, 0);
  b = map(b, 0, 255, 255, 0);

  analogWrite(R_PIN, r);
  analogWrite(G_PIN, g);
  analogWrite(B_PIN, b);
}

error: pathspec 'statusbot.ino' did not match any file(s) known to git


Arduino Sketch

Arduino Sketch

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MacgyverPT/Arduino-RC_Car.git/'


arduino code

arduino code

#include <SoftwareSerial.h>

#define SHORT_DELAY 200
#define LONG_DELAY 5000

#define RX 10 //SoftwareSerial RX pin
#define TX 11 //SoftwareSerial TX pin
#define BAUD 9600 //Baudrate for Serial and SoftwareSerial

//Bluetooth object
SoftwareSerial bluetooth(RX, TX);

#define ledPin 13 //choose the pin for LED
#define inputPin 7 // choose the input pin (for PIR Sensor)

int pirState = LOW; //Assuming no motion detected at starting point

int val = 0; //Variable for reading the pin status

void setup(void){
  pinMode(ledPin, OUTPUT);
  pinMode(inputPin, INPUT);
  bluetooth.begin(BAUD);
  Serial.begin(BAUD);
}

//Strings for motion detection and threat alert
char* motionDetected = "Motion detected!";
char* potentialThreat = "Potential Threat Alert!";

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println(motionDetected);
      bluetooth.println(motionDetected);
      // We only want to print on the output change, not state
      pirState = HIGH;
      delay(LONG_DELAY);
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println(potentialThreat);
      bluetooth.println(potentialThreat);
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }

  delay(SHORT_DELAY);
}

error: pathspec 'BeachAsif-EEE/pir_code/pir_code.ino' did not match any file(s) known to git


Try to save power

Try to save power

Normal ~7mA
During sleep ~0.35mA

Signed-off-by: Thomas Pfeiffer <a9319bcf77f61437a92bebec82799bc445aa951b@gmail.com>

//
// Test Deep Sleep
//

// Info from :
// http://www.insidegadgets.com/2011/02/05/reduce-attiny-power-consumption-by-sleeping-with-the-watchdog-timer/
// http://www.nongnu.org/avr-libc/
// https://kalshagar.wikispaces.com/Watchdog+as+interrupt
// http://oregonembedded.com/batterycalc.htm

#include <avr/wdt.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

#undef ECO // Power Saving On/Off ?

int setupLed = 3;
int loopLed = 4;

volatile boolean isOn = true;

// WatchDog interruption
EMPTY_INTERRUPT(WDT_vect);

void setup() {
  //
  // Setup
  pinMode(setupLed,OUTPUT);
  pinMode(loopLed,OUTPUT);
  digitalWrite(setupLed,HIGH);
  digitalWrite(loopLed,HIGH);

  delay(1000);

#ifdef ECO
  // Turn Off ADC
  power_adc_disable();

  // Turn Off USI
  power_usi_disable();

  // Setup WatchDog
  setupWatchdog();
#endif

  digitalWrite(setupLed,LOW);
}

void loop() {

  if(isOn)
  {
    digitalWrite(loopLed,LOW);
  }
  else{
    digitalWrite(loopLed,HIGH);
  }

  // Toggle
  isOn=!isOn;

  deepSleep();
}

void deepSleep()
{
#ifndef ECO

  delay(8000);

#else

  // Power Down
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // Stop Interruption
  cli();
  sleep_enable();
  //sleep_bod_disable(); // Turn Off BOD

  // Start interrupt then go to sleep !
  sei();
  sleep_cpu(); // Bye Bye

  sleep_disable(); // Wake Up

#endif
}

#ifdef ECO
//setup the watchdog to timeout every 8 second and make an interrupt (not a reset!)
void setupWatchdog(){
  //README : must set the fuse WDTON to 0 to enable the watchdog

    //disable interrupts
  cli();

  //make sure watchdod will be followed by a reset (must set this one to 0 because it resets the WDE bit)
  MCUSR &= ~(1 << WDRF);
  //set up WDT interrupt (from that point one have 4 cycle to modify WDTCSR)
  WDTCR = (1<<WDCE)|(1<<WDE);
  //Start watchdog timer with 1s prescaller and interrupt only
  WDTCR = (1<<WDIE)|(0<<WDE)|(1<<WDP3)|(1<<WDP0);

  //Enable global interrupts
  sei();
}
#endif

error: pathspec 'DeepSleep/DeepSleep.ino' did not match any file(s) known to git


HTTP interface

HTTP interface

/*
 SONOFF BASIC: firmware
 More info: https://github.com/tschaban/SONOFF-BASIC-firmware
 LICENCE: http://opensource.org/licenses/MIT
 2016-10-27 tschaban https://github.com/tschaban
*/

void startHTTPInterface() {
  if (Configuration.debugger) Serial << endl << " - Starting web server" << endl;
  server.on("/", handleHTTPInterfaceCommand);
  server.on("/favicon.ico",handleFavicon);
  server.onNotFound(handleNotFound);
  server.begin();
  if (Configuration.debugger) Serial << " - Web server is working" << endl;
}

void handleHTTPInterfaceCommand() {
  String _status = "{'status':'success'}";

  if (server.args()==1) {
    if (server.arg(0)=="on") {
      Relay.on();
    } else if (server.arg(0)=="off") {
      Relay.off();
    } else if (server.arg(0)=="configurationMode") {
      Sonoff.toggle();
    } else if (server.arg(0)=="reboot") {
      ESP.restart();
    } else {
      _status = "{'status':'not implemented'}";
    }
  } else {
    _status = "{'status':'failure'}";
  }

  server.send(200, "text/json", _status);
}

error: pathspec 'src/sonoff-interface-http.ino' did not match any file(s) known to git


Moved into project

Moved into project

#include <MIDI.h>

#include <avr/interrupt.h> // Use timer interrupt library

void flash(){
  digitalWrite(13, !digitalRead(13));
  delay(10);
  digitalWrite(13, !digitalRead(13));
}

void error(int i){
  while(true){
    for(int j = 0; j < i; j++){
      flash();
      delay(100);
    }
    delay(400);
  }
}

void swap (unsigned int *a, unsigned int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}
/*
void randomize ( unsigned int arr[], int n ){

    // Start from the last element and swap one by one. We don't
    // need to run for the first element that's why i > 0
    for (int i = n-1; i > 0; i--)
    {
        // Pick a random index from 0 to i
        int j = random(i+1);

        // Swap arr[i] with the element at random index
        swap(&arr[i], &arr[j]);
    }
}
*/

#define NOTECOUNT 127
unsigned int period[NOTECOUNT];

#define REFPD 2273
#define REFIX 57
#define TUNING 1.05946309436

void generate_period(){
  for(int i = 0; i < NOTECOUNT; i++){
    period[i] = REFPD * pow(TUNING, REFIX - i);
  }

  //randomize(period + 40, 60);
}

#define VOICECOUNT 8
struct voice{
  unsigned long time;
  unsigned int period;
  byte note;
  boolean on : 1;
  boolean up : 1;
};

voice voices[VOICECOUNT];

MIDI_CREATE_DEFAULT_INSTANCE();

void setup(){

  pinMode(13, OUTPUT); //debug LED

  MIDI.begin();
  MIDI.setHandleNoteOn(HandleNoteOn);
  MIDI.setHandleNoteOff(HandleNoteOff);

  /****Set timer1 for 8-bit fast PWM output ****/
  pinMode(9, OUTPUT); // Make timer’s PWM pin an output
  TCCR1B = (1 << CS10); // Set prescaler to full 16MHz
  TCCR1A |= (1 << COM1A1); // Pin low when TCNT1=OCR1A
  TCCR1A |= (1 << WGM10); // Use 8-bit fast PWM mode
  TCCR1B |= (1 << WGM12);
  //write to OCR1AL to adjust voltage

//  /******** Set up timer2 to call ISR ********/
//  TCCR2A = 0; // No options in control register A
//  TCCR2B = (1 << CS21); // Set prescaler to divide by 8
//  TIMSK2 = (1 << OCIE2A); // Call ISR when TCNT2 = OCRA2
//  OCR2A = 255; // Set frequency of wave updates
//  //freq = 16MHz / prescaler / OCR2A = 62.5 kHz

  generate_period();

//  sei(); // Enable interrupts to generate waveform!

}

void loop(){
  unsigned long now = micros();

  byte von = 0;
  byte vup = 0;

  for(int i = 0; i<VOICECOUNT; i++){
    if(voices[i].on){
      von++;
    } else {
      continue;
    }

    if(now > voices[i].time){
      voices[i].time += voices[i].period;
      voices[i].up = !voices[i].up;
    }
    if(voices[i].up){
      vup++;
    }
  }

  OCR1AL = 255 / von * vup;
}

void serialEvent(){
  MIDI.read();
}

//ISR(TIMER0_COMPA_vect){
//  flash();
//  static unsigned long now = micros();
//
//  for(int i = 0; i < VOICECOUNT; i++){
//    if(voices[i].vel == 0 && voices[i].lastvel == 0)
//      continue;
//
//    if(now > voices[i].time){
//      voices[i].time = now + period[voices[i].note];
//      if(voices[i].lastvel == 0){
//        OCR1AL += voices[i].vel;
//        voices[i].lastvel = voices[i].vel;
//      } else {
//        OCR1AL -= voices[i].lastvel;
//        voices[i].lastvel == 0;
//      }
//    }
//  }
//  flash();
//}

void HandleNoteOff (byte channel, byte note, byte velocity){
  //flash();
  static byte lastOff = 128;

  for(int i = 0; i < VOICECOUNT; i++){
    if(voices[i].note == note){
      /*if(lastOff >= 128){
        lastOff = note;
      } else {
        swap(&period[note], &period[lastOff]);
        lastOff = 128;
      }*/
      voices[i].on = false;
    }
  }
}

void HandleNoteOn (byte channel, byte note, byte velocity){
  //flash();
  if(velocity == 0){
    HandleNoteOff(channel,note,velocity);
    return;
  }

  for(int i = 0; i < VOICECOUNT; i++){
    if(voices[i].on == 0){
      voices[i] = {micros(), period[note], note, true, false};
      break;
    }
  }
}

error: pathspec 'polySynth.ino' did not match any file(s) known to git


add simple ChibiOS example sketch

add simple ChibiOS example sketch

/// @dir chiBlink
/// Simple LED blinker using the ChibiOS real-time operating system
/// @see http://jeelabs.org/2013/05/24/blinking-in-real-time/
// 2013-05-23 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <ChibiOS_AVR.h>

static WORKING_AREA(waThread1, 50);

void Thread1 (void* arg) {
  const uint8_t LED_PIN = 9;
  pinMode(LED_PIN, OUTPUT);

  while (1) {
    digitalWrite(LED_PIN, LOW);
    chThdSleepMilliseconds(100);
    digitalWrite(LED_PIN, HIGH);
    chThdSleepMilliseconds(500);
  }
}

void setup () {
  chBegin(mainThread);
}

void mainThread () {
  chThdCreateStatic(waThread1, sizeof (waThread1),
                    NORMALPRIO + 2, (tfunc_t) Thread1, 0);
  while (true)
    loop();
}

void loop () {
  delay(1000);
}

error: pathspec 'examples/RTOS/chiBlink/chiBlink.ino' did not match any file(s) known to git


Adicionando exemplo de uso do Dojo Shield com fita LED WS2811

/*

  Autor: Pitanga <pitanga@members.fsf.org> com base em sketches preexistentes

  Com código de Mark Kriegsman, July 2012
  as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
  e Fire2012 with programmable Color Palette (ver exemplos da FastLED para comentários
  específicos)

  Este sketch é uma variante do WildSnakeGS que usa o LDR para a velocidade e, ainda
  por cima, controla uma fita de LED de acordo com a "temperatura corporal" da cobrinha!

  Para controlar a fita led (WS2811, mas poderia ser qualquer outra suportada pela lib)
  usamos a biblioteca FastLED.

  A ideia é simples: a cobra é um répti, portanto um animal pecilotermo...

  Na presença da luz do sol, a temperatura e o metabolismo dos pecilotermos aumentam,
  portanto eles ficam mais ágeis. Na ausência da luz do sol, ficam mais frios e
  lentos, ou até dormindo!

  Para o usuário final, o circuito funciona assim:

  - Após o reset, o segmento inferior do display pisca por 3 segundos. Neste
  momento o usuário deve reduzir a incidência de luz no LDR para calibrar
  o nível inferior de luminosidade.

  - Em seguida o segmento central acende por 1 segundo para indicar que a
  calibragem do nível inferior encerrou e o usuário deve se preparar para
  a calibragem do nível superior.

  - O segmento superior do display pisca por 3 segundos para que o usuário
  aumente a incidência de luz no LDR e assim calibre o nível superior de
  luminosidade.

  - Após as duas calibragens, o circuito passa a ajustar continuamente a
  velocidade da cobrinha conforme a luz incidente no LDR.

  - O circuito também atualiza a paleta de cores do efeito "Fire" da fita
  LED de acordo com a leitura do LDR.

  Sobre como funciona a parte da cobrinha: ver exemplo WildSnakeGS
*/

#define DEBUG 1

// {first_choice, second_choice*}
// * -1 means there is no second_choice
int moves[][2] = {
  {1, -1},  // 0
  {13, 2},  // 1
  {3, -1},  // 2
  {4, -1},  // 3
  {6, 5},   // 4
  {0, -1},  // 5
  {2, 8},   // 6
  {12, -1}, // 7
  {7, -1},  // 8
  {13, 8},  // 9
  {9, -1},  // 10
  {10, -1}, // 11
  {6, 11},  // 12
  {5, 11}   // 13
};

/*     A
     -----
  F |     | B
    |  G  |
     -----
  E |     | C
    |  D  |
     -----
*/

//                A   B  C  D  E   F   G
int display[] = {8, 9, 10, 11, 12, 13, 7}; // Garoa Dojo Shield
const int SEGMENTS = 7;

int head = 1; // segment B
int tail = 0; // segment A

// variáveis para calibração
int seg_alto = 8;
int seg_meio = 7;
int seg_baixo = 11;
int ldr = A1;
int ldr_min = 0;
int ldr_max = 0;
int delay_min = 10;
int delay_max = 700;
int hue_frio = 235;
int hue_quente = 0;
int brilho_baixo = 50;
int brilho_alto = 200;
//para permitir colocar luz forçada além do maximo calibrado (ex. lanterna)
float extra_factor = 0.1;

int const QT_AMOSTRA = 100;
int const TEMPO_AMOSTRAGEM = 3000;

/*
 * FastLED parameters and variables
 */

#include <FastLED.h>

#define LED_PIN     5
#define COLOR_ORDER GRB
#define CHIPSET     WS2811
#define NUM_LEDS    30

#define FRAMES_PER_SECOND 60

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];

// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames.  More cooling = shorter flames.
// Default 55, suggested range 20-100
#define COOLING  50

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire.  Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 100

CRGBPalette16 gPal;

void setup() {
  //dojo shiels setup
  if (DEBUG){
    Serial.begin(9600);
  }

  for (int i = 0; i < SEGMENTS; i++) {
    pinMode(display[i], OUTPUT);
  }

  //FastLED setup
  delay(3000); // sanity delay
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

  //calibração
  ldr_min = amostragem(ldr, seg_baixo);
  digitalWrite(seg_meio, HIGH);
  delay(2000);
  digitalWrite(seg_meio, LOW);
  ldr_max = amostragem(ldr, seg_alto);

  //inicialização
  digitalWrite(display[tail % 7], HIGH);
}

void loop() {
  int valor_ldr = leitura_ldr();
  int valor_delay = map_delay(valor_ldr);
  int valor_hue = map_hue(valor_ldr);
  int valor_brilho = map_brilho(valor_ldr);

  if (DEBUG) {
    log_valores(valor_ldr, valor_delay, valor_hue, valor_brilho);
  }

  setColorPalette(valor_hue);
  FastLED.setBrightness(valor_brilho);
  Fire2012WithPalette(); // run simulation frame, using palette colors
  FastLED.show(); // display this frame
  digitalWrite(display[head % 7], HIGH);
  delay(valor_delay);
  digitalWrite(display[tail % 7], LOW);
  tail = head;
  int* choices = moves[head];
  if (choices[1] == -1) {
    head = choices[0];  // no second choice
  } else {
    head = choices[random(2)];  // random move
  }
}

int cmp(const void *x, const void *y) {
  return (*(int *)x - * (int *)y);
}

int mediana(int amostra[], int qt_amostra) {
  qsort(amostra, qt_amostra, sizeof(int), cmp);
  return amostra[qt_amostra / 2];
}

int amostragem(int pino_leitura, int pino_sinal) {
  int amostra [QT_AMOSTRA];
  for (int i = 0; i < QT_AMOSTRA; i++) {
    if (i % 6 == 0) digitalWrite(pino_sinal, HIGH);
    amostra[i] = analogRead(pino_leitura);
    delay(TEMPO_AMOSTRAGEM / QT_AMOSTRA);
    if (i % 6 == 3) digitalWrite(pino_sinal, LOW);
  }
  digitalWrite(pino_sinal, LOW);
  return mediana(amostra, QT_AMOSTRA);
}

int leitura_ldr() {
  return (int)constrain(analogRead(ldr), ldr_min , ldr_max);
}

int map_delay(int leitura_ldr) {
  return (int)map(leitura_ldr, ldr_min, ldr_max, delay_max, delay_min);
}

int map_hue(int leitura_ldr) {
  return (int)map(leitura_ldr, ldr_min, ldr_max, hue_frio, hue_quente);
}

int map_brilho(int leitura_ldr) {
  return (int)map(leitura_ldr, ldr_min, ldr_max, brilho_baixo, brilho_alto);
}

void setColorPalette(int valor_hue)
{
  // Add entropy to random number generator; we use a lot of it.
  random16_add_entropy( random());

  // Four different static color palettes are provided here, plus one dynamic one.
  //
  // The three static ones are:
  //   1. the FastLED built-in HeatColors_p -- this is the default, and it looks
  //      pretty much exactly like the original Fire2012.
  //
  //  To use any of the other palettes below, just "uncomment" the corresponding code.
  //
  //   2. a gradient from black to red to yellow to white, which is
  //      visually similar to the HeatColors_p, and helps to illustrate
  //      what the 'heat colors' palette is actually doing,
  //   3. a similar gradient, but in blue colors rather than red ones,
  //      i.e. from black to blue to aqua to white, which results in
  //      an "icy blue" fire effect,
  //   4. a simplified three-step gradient, from black to red to white, just to show
  //      that these gradients need not have four components; two or
  //      three are possible, too, even if they don't look quite as nice for fire.
  //
  // The dynamic palette shows how you can change the basic 'hue' of the
  // color palette every time through the loop, producing "rainbow fire".

  // Fourth, the most sophisticated: this one sets up a new palette every
  // time through the loop, based on a hue that changes every time.
  // The palette is a gradient from black, to a dark color based on the hue,
  // to a light color based on the hue, to white.
  //
  static uint8_t hue = valor_hue;
  CRGB darkcolor  = CHSV(hue, 255, 192); // pure hue, three-quarters brightness
  CRGB lightcolor = CHSV(hue, 128, 255); // half 'whitened', full brightness
  gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB::White);

}

// This basic one-dimensional 'fire' simulation works roughly as follows:
// There's a underlying array of 'heat' cells, that model the temperature
// at each point along the line.  Every cycle through the simulation,
// four steps are performed:
//  1) All cells cool down a little bit, losing heat to the air
//  2) The heat from each cell drifts 'up' and diffuses a little
//  3) Sometimes randomly new 'sparks' of heat are added at the bottom
//  4) The heat from each cell is rendered as a color into the leds array
//     The heat-to-color mapping uses a black-body radiation approximation.
//
// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
//
// This simulation scales it self a bit depending on NUM_LEDS; it should look
// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
//
// I recommend running this simulation at anywhere from 30-100 frames per second,
// meaning an interframe delay of about 10-35 milliseconds.
//
// Looks best on a high-density LED setup (60+ pixels/meter).
void Fire2012WithPalette()
{
  // Array of temperature readings at each simulation cell
  static byte heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
  for ( int i = 0; i < NUM_LEDS; i++) {
    heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  }

  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for ( int k = NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  }

  // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  if ( random8() < SPARKING ) {
    int y = random8(7);
    heat[y] = qadd8( heat[y], random8(160, 255) );
  }

  // Step 4.  Map from heat cells to LED colors
  for ( int j = 0; j < NUM_LEDS; j++) {
    // Scale the heat value from 0-255 down to 0-240
    // for best results with color palettes.
    byte colorindex = scale8( heat[j], 240);
    CRGB color = ColorFromPalette( gPal, colorindex);
    int pixelnumber;
    if ( gReverseDirection ) {
      pixelnumber = (NUM_LEDS - 1) - j;
    } else {
      pixelnumber = j;
    }
    leds[pixelnumber] = color;
  }
}

void log_valores(int v_ldr, int v_delay, int v_hue, int v_brilho) {
  Serial.print("ldr: ");
  Serial.print(v_ldr, DEC);
  Serial.print(", delay: ");
  Serial.print(v_delay, DEC);
  Serial.print(", hue: ");
  Serial.print(v_hue, DEC);
  Serial.print(", brilho: ");
  Serial.print(v_brilho, DEC);
  Serial.println("");
}

error: pathspec 'arduino/FireSnakeLDR/FireSnakeLDR.ino' did not match any file(s) known to git


Added pointer classes test

Added pointer classes test

# 2 "TestPointers.ino"

#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
#include <StandardCplusplus.h>
#include <RabirdToolkit.h>

#include <RTest.h>
#include <RRawPointer.h>
#include <RSharedPointer.h>

RTEST(TestRawPointer)
{
  // This pointer will not be free forever
  uint8_t *ptr  = new uint8_t(0xFA);
  uint8_t *ptr2 = new uint8_t(0xFA);

  RRawPointer<uint8_t> rawPtr;
  RRawPointer<uint8_t> rawPtr2(ptr);
  RRawPointer<uint8_t> rawPtr3(rawPtr2);

  RASSERT_TRUE(rawPtr.data() == NULL);
  RASSERT_TRUE(rawPtr2.data() == ptr);
  RASSERT_TRUE(rawPtr3.data() == ptr);
  RASSERT_TRUE(rawPtr3.data() == rawPtr2.data());
  RASSERT_TRUE(rawPtr == NULL);
  RASSERT_TRUE(rawPtr2 == ptr);
  RASSERT_TRUE(rawPtr3 == ptr);
  RASSERT_TRUE(rawPtr3 == rawPtr2.data());

  rawPtr.reset(ptr2);

  RASSERT_TRUE(rawPtr.data() == ptr2);

  rawPtr = rawPtr3;

  RASSERT_TRUE(rawPtr.data() == ptr);
  RASSERT_TRUE(rawPtr.data() == rawPtr2.data());

  rawPtr.reset();
  rawPtr3.reset();

  RASSERT_TRUE(rawPtr.data() == NULL);
  RASSERT_TRUE(rawPtr3.data() == NULL);
  RASSERT_TRUE(rawPtr == NULL);
  RASSERT_TRUE(rawPtr3 == NULL);
  RASSERT_TRUE(rawPtr2 == ptr);
};

void
setup()
{
  Serial.begin(9600);

  while(!Serial)  // for the Arduino Leonardo/Micro only
  {
  }

  RTestApplication testApp;

  testApp.addTest(&RTEST_INSTANCE(TestRawPointer));
  testApp.run();
}

void
loop()
{
}

error: pathspec 'tests/TestPointers/TestPointers.ino' did not match any file(s) known to git


add base file

add base file

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

error: pathspec 'Teensy_Reactor_Controller.ino' did not match any file(s) known to git


this one works

this one works

// *******libraries
#include <Adafruit_NeoPixel.h>
#include <Stepper.h>

// *******these constants won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to (may be legacy for pre-neopixel)
//LED constants
const int neoPin = 11;         //neopixel control pin
const int pixelQuant = 1;     // number of neopixels
//sound Pin
const int upPin = 4;
const int pingPin = 3;
const int downPin = 5;
// how long the on period should be
const int onTime = 300;

// *******these variables will change:
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int counter = 0;
int stateTracker = 0;          // used to prevent double off-sequencing
int pingTracker = 0;        // used to make the ping in the on phase happen only once
//LED variables
int redVal = 255;            // used to fade out LED. Starts at 255 to match startup val
int greenVal = 0;             //used to fade in LED
//stepper variables
//number of steps you want the motor to take
#define STEPS 600

//********other initialization things
// intitialize neopixel object
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelQuant, neoPin, NEO_RGB + NEO_KHZ800);
// create an instance of the stepper, specifiying number of steps and pins
Stepper stepper(STEPS, 7, 8, 9, 10);

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

  //initialize neopixels
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  //initialize the stepper
  // speed in RPM - keep it below 25
  stepper.setSpeed(10);

  //initilizes the audio pin
  pinMode(upPin,OUTPUT);
  digitalWrite(upPin, HIGH);
  pinMode(pingPin,OUTPUT);
  digitalWrite(pingPin, HIGH);
  pinMode(downPin,OUTPUT);
  digitalWrite(downPin, HIGH);
}

void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  //****************************************************
  /* state change sequences */
  //****************************************************

  // compare the buttonState to its previous state and see if it changed
  if (buttonState != lastButtonState) {
    // Delay a little bit to avoid bouncing
    delay(50);
    // if the state changed, the switch is high, and the flag is down
    //pushing the button means that it is time for startup
    if ((buttonState == HIGH) && (counter == 0)) {

      startup();

    }

    //if the state changed, the switch is high, and the flag is up
    // pushing the botton means that it is time to shut down early
    //conter >1 instead of >0 becasue it gets set to 1 in startup so will be 1 before completing this
    //sub routine
    if ((buttonState == HIGH) && (counter > 1)) {
      turnoff();
    }

  }

  //****************************************************
  /* while it is on sequences */
  //****************************************************

  // if the counter > 0 the startup sequence has been initiated
  if ((counter > 0) && (counter < onTime)) {
    on();
  }

  // if counter > onTime it is time to shut down
  if (counter > (onTime-1)) {
    turnoff();
  }

  //****************************************************
  /* housecleaning sequence */
  //****************************************************
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;

}

//****************************************************
/* functions */
//****************************************************

// this function is "void" becuase it is not expected to return a value - it just does something
// this is the startup  sequence where it flashes the LED on 3 times for 1 second each and then stays on
void startup() {
  Serial.println("starting");

  //*******LED section
  ////this section is optional for if you want a color on during the on sequence
  ////I think you don't, but just in case I'm leaving it as a placeholder
  ////sets the color
  //strip.setPixelColor(0, 255, 0, 0); //pixel number, r,g,b
  ////pushes change to neopixels
  //strip.show();

  //*******Tone section
  //trigger the sound
  digitalWrite(upPin, LOW);
  delay(200);
  digitalWrite(upPin, HIGH);

  //*******Stepper section
  //goes up STEPS steps
  stepper.step(STEPS);

  //*******cleanup section
  counter = 1;
  stateTracker = 1;
  pingTracker = 0;
  Serial.println("Startup complete");

}

// this is the on function
void on() {
  Serial.println("On");

  //***** Tone Section
  //trigger the ping
  //^^^^^^^^NOTE: ping won't trigger if the startup song ends after the stepper stops in startup()^^^^^
  if (pingTracker == 0) {
    digitalWrite(pingPin, LOW);
    delay(200);
    digitalWrite(pingPin, HIGH);
    //tells the variable that ping has already happened
    pingTracker = 1;
  }

  //*****LED section
  // allows the LED to fade out
  // counter is how far it is into the counter sequence
  // 0 is the lowest counter number, 100 is the highest number
  // 255 is where the output number should start (because it is on when counter = 0
  // 0 is where the output ends when the counter  hits 100
  redVal = map(counter, 0, onTime, 255, 0);
  // turns up the green as the red fades out
  greenVal = map(counter, 0, onTime, 0, 255);
  //sets the color
  strip.setPixelColor(0, redVal, greenVal, 0); //pixel number, r,g,b
  //pushes change to neopixels
  strip.show();

  //******cleanup section
  //increases counter
  counter += 1;
  Serial.print("Counter is: ");
  Serial.println(counter);
}

//  this is the shutdow function
void turnoff() {
  Serial.println("shutdown");

  //***** Tone Section
  //trigger the down music
  digitalWrite(downPin, LOW);
  delay(200);
  digitalWrite(downPin, HIGH);
  //this is for the on ping reset
  pingTracker = 0;

  //*****LED section
  // turns off neopixels
  strip.setPixelColor(0, 0, 0, 0); //pixel number, r,g,b
  strip.show();

  //*****stepper section
  // goes down STEPS steps (down because it is negative)
  stepper.step(-STEPS);

  //*****cleanup section
  counter = 0;
  stateTracker = 0;

}

error: pathspec 'led_sequence_combined_momentary_mar2019/led_sequence_combined_momentary_mar2019.ino' did not match any file(s) known to git


Create droneBluetooth.ino

Create droneBluetooth.ino

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/GaParmar/quadcopter.git/'


Example: Add output tone testing example

/*
  Output Tone With Stepped Amplitude

  Chip Audette, OpenAudio 2018

  Plays a single tone followed by silence.  Repeats the tone+silence at increasing amplitude.
  The last tone should definitely distort.  The 2nd-to-last tone should be on the edge of distorting.

  MIT License, Use at your own risk.
*/

#include <Tympan_Library.h>

//set the sample rate and block size
const float sample_rate_Hz = 44117.0f ; //24000 or 44117 (or other frequencies in the table in AudioOutputI2S_F32)
const int audio_block_samples = 128;     //do not make bigger than AUDIO_BLOCK_SAMPLES from AudioStream.h (which is 128)
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);

// Create the audio library objects that we'll use
TympanPins                tympPins(TYMPAN_REV_C);     //TYMPAN_REV_C or TYMPAN_REV_D
TympanBase                tympanHardware(tympPins);   //from the Tympan_Library
AudioSynthWaveform_F32    sineWave;                   //from the Tympan_Library
AudioOutputI2S_F32        audioOutput(audio_settings);//from the Tympan_Library

// Create the audio connections from the sineWave object to the audio output object
AudioConnection_F32 patchCord10(sineWave, 0, audioOutput, 0);  //connect to left output
AudioConnection_F32 patchCord11(sineWave, 0, audioOutput, 1);  //connect to right output

// Define the parameters of the tone
float tone_freq_Hz = 1000.0;   //frequency of the tone
#define N_AMP (8)              //How many different amplitudes to test
float tone_amp[N_AMP] = {0.1, 0.2, 0.4, 0.5, 0.6, 0.8, 1.0, 1.2};     //here are the amplitudes (1.0 is digital full scale) to test
float tone_dur_msec = 1000.0;  // Length of time for the tone, milliseconds
int amp_index = N_AMP-1;       //a counter to use when stepping through the given amplitudes

// define setup()...this is run once when the hardware starts up
void setup(void)
{
  //Open serial link for debugging
  Serial.begin(115200); delay(500);
  Serial.println("OutputTone: starting setup()...");

  //allocate the audio memory
  AudioMemory(10); AudioMemory_F32(20,audio_settings); //I can only seem to allocate 400 blocks
  Serial.println("OutputTone: memory allocated.");

  //set the sine wave parameters
  sineWave.frequency(tone_freq_Hz);
  sineWave.amplitude(0.0);
  tympanHardware.setAmberLED(LOW);

  //start the audio hardware
  tympanHardware.enable();

  //Set the baseline volume levels
  tympanHardware.volume_dB(0);                   // headphone amplifier.  -63.6 to +24 dB in 0.5dB steps.

  Serial.println("Setup complete.");
}

// define loop()...this is run over-and-over while the device is powered
#define START_SILENCE 0
#define PLAY_SILENCE 1
#define START_TONE 2
#define PLAY_TONE 3
int state = START_SILENCE;
unsigned long start_time_millis = 0;
float silence_dur_msec = 1000.f;
int iteration_count = 0;
void loop(void)
{
  switch (state) {
    case START_SILENCE:
      sineWave.amplitude(0.0f);
      start_time_millis = millis();
      tympanHardware.setAmberLED(LOW);
      state = PLAY_SILENCE;
      break;
    case PLAY_SILENCE:
      if ((millis() - start_time_millis) >= silence_dur_msec) {
        state = START_TONE;
      }
      break;
    case START_TONE:
      amp_index++; if (amp_index == N_AMP) { amp_index = 0; iteration_count++;}
      sineWave.amplitude(tone_amp[amp_index]);
      Serial.print("Changing to start tone, amplitude = ");Serial.println(tone_amp[amp_index]);
      tympanHardware.setAmberLED(HIGH);
      start_time_millis = millis();
      state = PLAY_TONE;
      break;
    case PLAY_TONE:
      if ((millis() - start_time_millis) >= tone_dur_msec) {
        state = START_SILENCE;
        Serial.println("Changing to start silence...");
      }
      break;
  }
}

error: pathspec 'examples/02-Utility/OutputToneWithSteppedAmplitude/OutputToneWithSteppedAmplitude.ino' did not match any file(s) known to git


Wi-Fiれこーだ多機能版

Wi-Fiれこーだ多機能版

/*******************************************************************************
Example 3: Wi-Fi レコーダ 多機能版

アナログ入力値、デジタル入力値、シリアル入力データをWi-Fi送信します。
アナログ入力を使用しないときはTOUTをGNDへ接続しておいてください。

                                          Copyright (c) 2016-2019 Wataru KUNINO
*******************************************************************************/

#include <ESP8266WiFi.h>                    // ESP8266用ライブラリ
extern "C" {
#include "user_interface.h"                 // ESP8266用の拡張IFライブラリ
}
#include <WiFiUdp.h>                        // UDP通信を行うライブラリ
#define PIN_SW 4                            // IO 4(10番ピン) にセンサを接続
#define PIN_LED 13                          // IO 13(5番ピン)にLEDを接続する
#define SSID "1234ABCD"                     // 無線LANアクセスポイントのSSID
#define PASS "password"                     // パスワード
#define SENDTO "192.168.0.255"              // 送信先のIPアドレス
#define PORT 1024                           // 送信のポート番号
#define DEVICE "adcnv_1,"                   // デバイス名(5文字+"_"+番号+",")

#define TRIG_BPS 9600                       // シリアル入力速度
#define TRIG_RISE 15                        // 上昇検出
#define TRIG_FALL 15                        // 下降検出

int adc_prev = 0;                           // 前回値（アナログ）
int din_prev = -1;                          // 前回値（デジタル）
char s[64];                                 // シリアル入力
int s_len = 0;                              // シリアル入力長

void setup(){                               // 起動時に一度だけ実行する関数
    pinMode(PIN_SW,INPUT_PULLUP);           // センサを接続したポートを入力に
    pinMode(PIN_LED,OUTPUT);                // LEDを接続したポートを出力に
    Serial.begin(TRIG_BPS);                 // シリアル出力・入力の開始
    Serial.println("Example 03 ADC");       // 「Example 03」をシリアル出力表示
    WiFi.mode(WIFI_STA);                    // 無線LANをSTAモードに設定
    WiFi.begin(SSID,PASS);                  // 無線LANアクセスポイントへ接続
    while(WiFi.status() != WL_CONNECTED){   // 接続に成功するまで待つ
        digitalWrite(PIN_LED,!digitalRead(PIN_LED));    // LEDの点滅
        delay(500);                         // 待ち時間処理
    }
    Serial.println(WiFi.localIP());         // 本機のIPアドレスをシリアル出力
}

void loop(){                                // 繰り返し実行する関数
    WiFiUDP udp;                            // UDP通信用のインスタンスを定義
    int adc,din;                            // 整数型変数adcとiを定義
    char c='\0';

    adc=system_adc_read();                  // AD変換器から値を取得
    din=digitalRead(PIN_SW);                // デジタル入力値を取得
    if(Serial.available()){
        c = Serial.read();
        if( isprint(c) ){
            s[s_len] = c;
            s_len++;
            if( s_len > 63 ) s_len=63;
            s[s_len] = '\0';
        }
    }
    if(
        ( adc > adc_prev - TRIG_FALL && adc < adc_prev + TRIG_RISE)
        && din == din_prev
        && c != '\n'
    ) return;                               // 変化が無ければloopの先頭に戻る
    digitalWrite(PIN_LED,HIGH);             // LED点灯
    udp.beginPacket(SENDTO, PORT);          // UDP送信先を設定
    udp.print(DEVICE);                      // デバイス名を送信
    udp.print(adc);                         // 変数adcの値を送信
    udp.print(", ");                        // 「,」カンマと「␣」を送信
    udp.print(din);                         // 変数dinの値を送信
    Serial.print(adc);                      // 変数adcの値をシリアル出力表示
    Serial.print(", ");                     // 「,」カンマと「␣」を出力表示
    Serial.print(din);                      // 変数dinの値をシリアル出力表示
    if(s_len > 0 && c == '\n'){
        udp.print(", ");                    // 「,」カンマと「␣」を送信
        udp.println(s);                     // 文字列変数sの内容を送信
        Serial.print(", ");                 // 「,」カンマと「␣」を出力表示
        Serial.println(s);                  // 文字列変数sの内容をシリアル出力
        s_len = 0;
    }else{
        udp.println();
        Serial.println();
    }
    udp.endPacket();                        // UDP送信の終了(実際に送信する)
    delay(100);                             // 100msの待ち時間処理
    digitalWrite(PIN_LED,LOW);              // LED消灯
    adc_prev = adc;                         // AD値を前回値として保存
    din_prev = din;                         // デジタル入力値を前回値として保存
}

error: pathspec '2_example/example03a_adc/example03a_adc.ino' did not match any file(s) known to git


very nice back and forth material effect

// try: dim at ends per cosine, bump into each other and transfer momentum

#include <PololuLedStrip.h>
#include <math.h>

// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<12> ledStrip;

#define EASE_EXPONENT 3 // cubic
#define EASE_COUNT 36
#define EASE_DELAY 5
#define EASE_ANIM_MARGIN 30

// Create a buffer for holding the colors (3 bytes per color).
#define ANIM_LED_COUNT 144
#define LED_COUNT (ANIM_LED_COUNT + EASE_ANIM_MARGIN)
#define VLED_COUNT (LED_COUNT)
#define MAX_LED (LED_COUNT)
#define MAX_VLED (VLED_COUNT)
#define LED_COUNT_MIDPOINT (LED_COUNT / 2)

rgb_color colors[LED_COUNT];
unsigned char existence[VLED_COUNT];

float ease[LED_COUNT];

#define DELAY 1000
#define FADE_RATE 0.75
#define FADE_COUNT 20

#define BRIGHTNESS_PERCENT 25
#define BRIGHTNESS_DIVISOR 20.0
#define MIN_BRIGHTNESS 1.0

#define RESOLUTION 1000000.0

#define MIN_SPEED 0.50
#define MAX_SPEED 0.75
#define SPEED MIN_SPEED

#define NUM_ROWS 10
#define NUM_COLS 17
#define MAX_ROW (NUM_ROWS - 1)
#define MAX_COL (NUM_COLS - 1)

rgb_color black = {0, 0, 0};
rgb_color gray = {10, 10, 10};
rgb_color white = {20, 20, 20};
rgb_color red = {20, 0, 0};
rgb_color orange = {20, 10, 0};
rgb_color yellow = {20, 20, 0};
rgb_color ltgreen = {10, 20, 0};
rgb_color green = {0, 20, 0};
rgb_color seafoam = {0, 20, 10};
rgb_color cyan = {0, 20, 20};
rgb_color ltblue = {0, 10, 20};
rgb_color blue = {0, 0, 20};
rgb_color purple = {10, 0, 20};
rgb_color magenta = {20, 0, 20};
rgb_color pink = {20, 0, 10};

#define NPALETTE 15
#define NPRETTY_COLORS 12
rgb_color palette[NPALETTE] = { red, orange, pink, magenta,      yellow, green, seafoam, ltgreen,       ltblue, cyan, blue, purple,        white, gray, black };

#define NGROUPS 3
#define GROUP_RED_START 0
#define GROUP_RED_MAX 4
#define GROUP_GREEN_START 4
#define GROUP_GREEN_MAX 8
#define GROUP_BLUE_START 8
#define GROUP_BLUE_MAX 12
#define GROUP_WHITE_START 12
#define GROUP_WHITE_MAX 13

int group_start[4] = {GROUP_RED_START,GROUP_GREEN_START,GROUP_BLUE_START,GROUP_WHITE_START};
int group_max[4] = {GROUP_RED_MAX,GROUP_GREEN_MAX,GROUP_BLUE_MAX,GROUP_WHITE_MAX};

rgb_color adjusted_palette[NPALETTE];

// 72 @ 2.0
int sin223_translation[223] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 53, 54, 54, 55, 55, 56, 56, 56, 57, 57, 58, 58, 58, 59, 59, 59, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 65, 65, 65, 66, 66, 66, 66, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71};

// 72 @ 5.0
// int sin557_translation[557] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71};

// 64 @ 2.0
// int sin198_translation[198] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, 49, 50, 50, 51, 51, 51, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63};

#define WARPED sin223_translation

#define NUM_OBJECTS 6

//#define MIN_PERIOD 50
//#define MAX_PERIOD 100

#define WIDTH 3

#define DECAY 0.0

unsigned char bitmask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

rgb_color scale_color(rgb_color color, float scale){
  return (rgb_color){
    ((color.red / BRIGHTNESS_DIVISOR) * 255) * scale,
    ((color.green / BRIGHTNESS_DIVISOR) * 255) * scale,
    ((color.blue / BRIGHTNESS_DIVISOR) *255) * scale
  };
}

void set_brightness(int brightness_percent = BRIGHTNESS_PERCENT){
  float percent = brightness_percent / 100.0;
  for(int i = 0; i < NPALETTE; i++){
    adjusted_palette[i] = scale_color(palette[i], percent);
  }
}

void flood(rgb_color color){
  for(int i = 0; i < LED_COUNT; i++){
    colors[i] = color;
  }
}

void erase(){
  flood(black);
}

void fade(float rate = FADE_RATE){
  unsigned char *p;
  p = (unsigned char *)colors;
  for(int i = 0; i < LED_COUNT * 3; i++){
    *(p + i) *= rate;
  }
}

void fade_fast(){
  unsigned char *p;
  p = (unsigned char *)colors;
  for(int i = 0; i < LED_COUNT * 3; i++){
    *(p + i) = *(p + i) >> 1;
  }
}

void fade_fast2(int rate = FADE_RATE){
  unsigned char *p;
  p = (unsigned char *)colors;
  for(int i = 0; i < LED_COUNT * 3; i++){
    *(p + i) = max(0, *(p + i) - rate);
  }
}

float random_dir(){
  float result = ((random(RESOLUTION) / RESOLUTION) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;

  result = random(2) == 1 ? result : result * -1.0;

  return result;

  //int range = random(RESOLUTION - MIN_SPEED) + MIN_SPEED;
  //return (range / (RESOLUTION * 1.0)) - 0.5;
}

int random_color(){
  return random(NPRETTY_COLORS);
}

int reflect_i(int *i, int *d, int mx, int mn = 0){
  int ld = *d;
  int next = *i + *d;
  if(next > mx || next < mn){
    *d *= -1;
  }
  *i += *d;

  int dir = 0;
  if(*d > ld){
    dir = 1;
  } else if(*d < ld){
    dir = -1;
  }
  return dir;
}

bool position_occupied(int pos, int id){
  return (existence[pos] & ~bitmask[id]) == 0 ? false : true;
}

float reflect_f(float *f, float *d, int id, float mx = 1.0, float mn = 0.0){
  float ld = *d;
  float last = *f;
  float next = *f + *d;

//  int lasti = WARPAGE[int(last)];
//  int nexti = WARPAGE[int(next)];
  int lasti = int(last);
  int nexti = int(next);

//  bool clash = (nexti != lasti) && position_occupied(nexti, id);
  bool clash =  position_occupied(nexti, id);

  if(next > mx || next < mn || clash){
    *d *= -1.0;
  }
  *f += *d;

  int dir = 0;
  if(*d > ld){
    dir = 1;
  } else if(*d < ld){
    dir = -1;
  }
  return dir;
}

int wrap_i(int i, int d, int mx){
  int next = i + d;
  if(next >= mx){
    return 0;
  } else {
    return next;
  }
}

float wrap_f(float f, float d, float mx = 1.0){
  float next = f + d;
  if(next >= mx){
    return 0.0;
  } else {
    return next;
  }
}

rgb_color add_color(rgb_color color1, rgb_color color2){
  rgb_color new_color;
  new_color.red = min(255, color1.red + color2.red);
  new_color.green = min(255, color1.green + color2.green);
  new_color.blue = min(255, color1.blue + color2.blue);
  return new_color;
}

rgb_color subtract_color(rgb_color color1, rgb_color color2){
  rgb_color new_color;
  new_color.red = max(0, color1.red - color2.red);
  new_color.green = max(0, color1.green - color2.green);
  new_color.blue = max(0, color1.blue - color2.blue);
  return new_color;
}

//swaps red & green, needed on led strands, not on strips
void setup_colors(bool swap = true){
  if(swap == true){
    for(int i = 0; i < NPALETTE; i++){
      unsigned char value = palette[i].red;
      palette[i].red = palette[i].green;
      palette[i].green = value;
    }
  }
  memcpy(adjusted_palette, palette, sizeof(palette));
}

void setup()
{
  randomSeed(analogRead(0));
  setup_colors(false);
  set_brightness();

  for(int i = 0; i < VLED_COUNT; i++){
     existence[i] = 0;
  }

  set_brightness(BRIGHTNESS_PERCENT);

  generate_shift_ease(EASE_COUNT, EASE_EXPONENT);
}

/*
#define MAX_BRIGHTNESS 20.0
#define BRIGHTNESS_STEP 2.0
*/

void poof(int color, int times=10, int brightness=50){
  set_brightness(brightness);
  for(int i = 0; i < times; i++){
    flood(black);
    ledStrip.write(colors, LED_COUNT);
    delay(33);
    flood(adjusted_palette[color]);
    ledStrip.write(colors, LED_COUNT);
    delay(33);
  }

  flood(black);
  ledStrip.write(colors, LED_COUNT);
  delay(33);
}

/*
void draw(rgb_color color, int pos, int num = 1){
  int side = num / 2;
  int left = max(0, pos - side);
  int right = min(LED_COUNT - 1, pos + side);

  for(int i = left; i <= right; i++){
    colors[i] = add_color(colors[i], color);
  }
}
*/

void draw(rgb_color color, int pos, int id = 0){
  if(pos < 0 || pos >= LED_COUNT) return;
  //int warped = WARPED[pos];
  colors[pos] = add_color(colors[pos], color);
  existence[pos] |= bitmask[id];
}

void undraw(rgb_color color, int pos, int id = 0){
  if(pos < 0 || pos >= LED_COUNT) return;
  //int warped = WARPED[pos];
  //colors[warped] = subtract_color(colors[warped], color);
  existence[pos] &= ~bitmask[id];
}

float decay(float value){
  float orig = value;
  if(value >= 0){
    value -= DECAY;
    if(value < 0){
      value = random_dir();
    }
  } else {
    value += DECAY;
    if(value > 0){
      value = random_dir();
    }
  }
  return value;
}

float ease_power_in(float percent, int power){
  return pow(percent, power);
}

float ease_power_out(float percent, int power){
  return 1 - pow(1 - percent, power);
}

float ease_elastic_out(float percent){
  return sin(-13 * M_PI_2 * (percent + 1)) * pow(2, -10 * percent) + 1;
}
// elastic in: return sin(13 * M_PI_2 * p) * pow(2, 10 * (p - 1));

void generate_power_ease(int count, int power){
  float midpoint = count / 2;
  for(int i = 0; i < midpoint; i++){
    float percent = i / midpoint;
    ease[i] = 0.5 * (ease_power_in(percent, power));
    ease[i + int(midpoint)] = (0.5 * (ease_power_out(percent, power))) + 0.5;
  }
}

// power ease in then elastic ease out
void generate_shift_ease(int count, int power){
  float midpoint = count / 2;
  for(int i = 0; i < midpoint; i++){
    float percent = i / midpoint;
    ease[i] = 0.5 * (ease_power_in(percent, power));
    ease[i + int(midpoint)] = (0.5 * (ease_elastic_out(percent))) + 0.5;
  }
}

void flush(){
  ledStrip.write(colors, LED_COUNT);
}

//#define MIN_SIZE 4

void loop()
{
  int lx = 0;
  int x = 0;

  while(true){
    lx = x;
    x = random(ANIM_LED_COUNT);
    rgb_color color = adjusted_palette[random_color()];

    int anim_start = lx;
    int anim_width = x - lx;
    int anim_dir = anim_width < 0 ? -1 : 1;
    if(anim_dir == -1){
      anim_width *= -1;
      anim_start = x;
    }

    for(int i = 0; i < EASE_COUNT; i++){
      fade_fast();
      int pos = ease[i] * anim_width;

      if(anim_dir == -1){
        pos = anim_width - pos;
      }

      draw(color,  pos + anim_start);
      flush();
      delay(EASE_DELAY);
    }
  }

//      for(int i = 0; i < FADE_COUNT; i++){
//        fade_fast();
//        draw(white, ANIM_LED_COUNT-1);
//        flush();
//        delay(EASE_DELAY);
//      }
//
//      erase();

//      for(int i = EASE_COUNT - 1; i >= 0; i--){
//        fade_fast();
//        int x = ease[i] * (LED_COUNT - ANIM_MARGIN);
//        if(x >= 0 && x < LED_COUNT){
//          draw(adjusted_palette[e],  x);
//        }
//        flush();
//        delay(EASE_DELAY);
//      }

//      delay(DELAY);
//    }

  return;

//  float x[NUM_OBJECTS];
//  float dx[NUM_OBJECTS];
//  int lx[NUM_OBJECTS];
//  int group[NUM_OBJECTS];
//  int period[NUM_OBJECTS];
//  int count[NUM_OBJECTS];
//  bool state[NUM_OBJECTS];
//  // int change[NUM_OBJECTS];
//  rgb_color show_color[NUM_OBJECTS];

//  int choices[NGROUPS];
//  for(int i = 0; i < NGROUPS; i++){
//    choices[i] = -1;
//  }

/*
  for(int i = 0; i < NGROUPS; i++){
    while(true){
      int color = random(NGROUPS);

      bool try_again = false;
      for(int j = 0; j < i; j++){
        if(color == choices[j]){
          try_again = true;
          break;
        }
      }
      if(try_again == true){
        continue;
      }

      choices[i] = color;
      break;
    }
  }
*/
//  for(int i = 0; i < NUM_OBJECTS; i++){
//    x[i] = i * (VLED_COUNT / NUM_OBJECTS);
//    dx[i] = random_dir();
////    dx[i] = 1.0;
//    lx[i] = -1;
////    period[i] = random(MIN_PERIOD, MAX_PERIOD);
////    count[i] = period[i];
////    state[i] = false;
//  }
//
//  rgb_color random_colors[NUM_OBJECTS];
//  for(int i = 0; i < NUM_OBJECTS; i++){
////    group[i] = choices[i % NGROUPS];
////    random_colors[i] = adjusted_palette[random(group_start[group[i]], group_max[group[i]])];
//    random_colors[i] = adjusted_palette[i];
////    show_color[i] = random_colors[i];
//  }
//
//  while(true){
//    //fade();
//    //erase();
//    fade_fast();
//    //fade_fast2();
//
//    for(int i = 0; i < NUM_OBJECTS; i++){
//      //change[i] =
//      reflect_f(&x[i], &dx[i], i, MAX_VLED);
//
//      //dx[i] = decay(dx[i]);
//
////      int tpos = WARPAGE[int(x[i])];
//      int tpos = int(x[i]);
////      if(tpos != lx[i]){
//        undraw(random_colors[i], lx[i], i);
//        draw(random_colors[i], tpos, i);
//        lx[i] = tpos;
////      }
//
////      if(lx != x[i]){
////        int lpos = sin223_translation[int(lx)];
////      }
//    }

/*
    for(int i = 0; i < NUM_OBJECTS; i++){
      if(change[i] == 0){
        if(position_occupied(int(x[i]), i)){
          dx[i] *= -1.0;
        }
      }
    }
*/

//    ledStrip.write(colors, LED_COUNT);
//    delay(DELAY);
//  }

}

int low_limit(int value, int limit){
  return value < limit ? limit : value;
}

int high_limit(int value, int limit){
  return value > limit ? limit : value;
}

int keep_in(int value, int lower, int upper){
  return low_limit(high_limit(value, upper), lower);
}

error: pathspec 'Arduino/shooting_colors/shooting_colors.ino' did not match any file(s) known to git


Delete D1M-WX1_IoT-APRS.ino

Delete D1M-WX1_IoT-APRS.ino

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/W4KRL/D1M-WX1-Weather-Station.git/'


little change

little change

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/TEAMarg/ID-37-DICE.git/'


Pince: update angle de la pince

Pince: update angle de la pince

error: pathspec 'Module' did not match any file(s) known to git
error: pathspec 'Pince/Moteur_deplacement/Moteur_deplacement/Moteur_deplacement.ino' did not match any file(s) known to git


add arduino sketch

add arduino sketch

int backwardsPin = 2;
int forwardsPin = 3;
int leftPin = 4;
int rightPin = 5;

int incomingByte = 0;

bool forwardsPressed = false;
bool backwardsPressed = false;
bool rightPressed = false;
bool leftPressed = false;

const int FORWARDS_PRESSED = 1;
const int FORWARDS_RELEASED = 2;
const int BACKWARDS_PRESSED = 131;
const int BACKWARDS_RELEASED = 4;
const int RIGHT_PRESSED = 133;
const int RIGHT_RELEASED = 134;
const int LEFT_PRESSED = 7;
const int LEFT_RELEASED = 8;

void setup() {
  pinMode(backwardsPin, OUTPUT);
  pinMode(forwardsPin, OUTPUT);
  pinMode(leftPin, OUTPUT);
  pinMode(rightPin, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  if (Serial.available() > 0) {
    incomingByte = Serial.read();

  }
}

void detectKeyPresses() {
  if (incomingByte == FORWARDS_PRESSED) {
      forwardsPressed = true;
    }
    else if (incomingByte == BACKWARDS_PRESSED) {
      backwardsPressed = true;
    }

    if (incomingByte == FORWARDS_RELEASED) {
      forwardsPressed = false;
    }
    else if (incomingByte == BACKWARDS_RELEASED) {
      backwardsPressed = false;
    }

    if (incomingByte == RIGHT_PRESSED) {
      rightPressed = true;
    }
    else if (incomingByte == LEFT_PRESSED) {
      leftPressed = true;
    }

    if (incomingByte == RIGHT_RELEASED) {
      rightPressed = false;
    }
    else if (incomingByte == LEFT_RELEASED) {
      leftPressed = false;
    }
}

void handlePinOutputs() {
  if (forwardsPressed == true) {
    digitalWrite(forwardsPin, HIGH);
  }
  else {
    digitalWrite(forwardsPin, LOW);
  }

  if (backwardsPressed == true) {
    digitalWrite(backwardsPin, HIGH);
  }
  else {
    digitalWrite(backwardsPin, LOW);
  }

  if (rightPressed == true) {
    digitalWrite(rightPin, HIGH);
  }
  else {
    digitalWrite(rightPin, LOW);
  }

  if (leftPressed == true) {
    digitalWrite(leftPin, HIGH);
  }
  else {
    digitalWrite(leftPin, LOW);
  }
}

error: pathspec 'rc-car-arduino/optocoupler-test.ino' did not match any file(s) known to git


added a sketch to try out the datalogging method

//some Arduino code to test out the GNU-Screen method
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(A0)); //it's okay to leave AO floating in this example, as it is just there to provide live data)
  delay(100);
}

error: pathspec 'GNU-Screen/example.ino' did not match any file(s) known to git


added potentiometer test

added potentiometer test

void setup() {
  Serial.begin(9000);

}

void loop() {
  Serial.println("RATE: ");
  Serial.println(analogRead(0));
  Serial.println("HUE: ");
  Serial.println(analogRead(1));
  Serial.println("VAL: ");
  Serial.println(analogRead(2));
  Serial.println("STROBE: ");
  Serial.println(analogRead(3));

  delay(400);

}

error: pathspec 'proj/pot_test/pot_test.ino' did not match any file(s) known to git


Example

Example

#include <glcdfont.h>
#include <minishift.h>

Minishift ms(3, 2, 4); // data_pin, clock_pin, latch_pin

void setup() {
  Serial.begin(57600);
}

void loop() {
  char buf[64];

  while(1) {
    int len = Serial.readBytesUntil('\n', buf, 63);
    buf[len] = '\0';
    ms.writeString(buf);
  }
}

error: pathspec 'examples/serialwrite/serialwrite.ino' did not match any file(s) known to git