Piano luminoso con EchidnaShield

Introducción

El objetivo es usar los conectores inferiores de EchidnaShield tocándolos con los dedos a modo de piano para que suene una nota musical diferente y cambien las luces RGB .

Nota: Poner el interruptor en la posición "MKMK"

Código en Bloques

Usando eBlock  puedes ejecutar el siguiente código sin realizar ningún cambio extra tanto en modo online ( necesario actualizar el firmware ) como subiéndolo a la placa.

Código Arduino

#include "eblock.h"

void whenPin_A0(uint8_t evt);
void whenPin_A1(uint8_t evt);
void whenPin_A2(uint8_t evt);
void whenPin_A3(uint8_t evt);
void whenPin_A4(uint8_t evt);
void whenPin_A5(uint8_t evt);

void setup(){
    Serial.begin(9600);
    register_callback(5, whenPin_A0);
    register_callback(6, whenPin_A1);
    register_callback(7, whenPin_A2);
    register_callback(8, whenPin_A3);
    register_callback(9, whenPin_A4);
    register_callback(10, whenPin_A5);
}

void loop(){
    _loop();
}

void _loop(){
      echidna_buttons_events();
      echidna_pins_events();
}

void whenPin_A0(uint8_t evt)
{
    e_pwm(9,100);e_pwm(5,0);e_pwm(6,0);
    tone(10, 65,500);
}

void whenPin_A1(uint8_t evt)
{
    e_pwm(9,200);e_pwm(5,0);e_pwm(6,0);
    tone(10, 73,500);
}

void whenPin_A2(uint8_t evt)
{
    e_pwm(9,0);e_pwm(5,100);e_pwm(6,0);
    tone(10, 82,500);
}

void whenPin_A3(uint8_t evt)
{
    e_pwm(9,0);e_pwm(5,200);e_pwm(6,0);
    tone(10, 87,500);
}

void whenPin_A4(uint8_t evt)
{
    e_pwm(9,0);e_pwm(5,0);e_pwm(6,100);
    tone(10, 98,500);
}

void whenPin_A5(uint8_t evt)
{
    e_pwm(9,0);e_pwm(5,0);e_pwm(6,200);
    tone(10, 123,500);
}

void echidna_led(uint8_t pin, uint8_t state ){
    	if(pin==0){ //ALL pins
                e_pin_set(11,state);
                e_pin_set(12,state);
                e_pin_set(13,state);
         }else{
                e_pin_set(pin,state);
        };
}

void echidna_buttons_events(){
       if( e_is_button_down(2) ) e_event_call(1);
       if( e_is_button_up(2) )   e_event_call(2);
       if( e_is_button_down(3) ) e_event_call(3);
       if( e_is_button_up(3) )   e_event_call(4);
}

void echidna_pins_events(){
        e_touch_level( 600 );
       if( e_touching(A0) )      e_event_call(5);
       if( e_touching(A1) )      e_event_call(6);
       if( e_touching(A2) )      e_event_call(7);
       if( e_touching(A3) )      e_event_call(8);
       if( e_touching(A4) )      e_event_call(9);
       if( e_touching(A5) )      e_event_call(10);
}

void register_callback( uint8_t event,   void (*in_main_func)()  ){
    	e_event( event, in_main_func);
}