Skip to content

Commit

Permalink
Merge pull request #263 from bobstanton/bluehand_sound_led
Browse files Browse the repository at this point in the history
Bluehand sound_led keymap
  • Loading branch information
jpconstantineau authored Jan 6, 2022
2 parents a20a7db + 2566a95 commit a37115e
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR P
#define MATRIX_ROWS 1
#define MATRIX_COLS 8
#define MATRIX_ROW_PINS { 33 }
#define MATRIX_COL_PINS { 29, 2, 28, 3, 10, 9, 24, 13}
/*
.---------------------------.
| 29 | 2 | 28 | 3 |
|------+------+------+------|
| 13 | 24 | 9 | 10 |
`---------------------------'
*/
#define MATRIX_COL_PINS { 29, 2, 28, 3, 13, 24, 9, 10}
#define LED_G 42 //Green LED
#define LED_R 36 //Red LED, the name LED_RED is defined elsewhere
#define UNUSED_PINS {}

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW
#define BATTERY_TYPE BATT_VDDH

#define SPEAKER_PIN 10
#define SPEAKER_PIN 45
#endif /* HARDWARE_CONFIG_H */
164 changes: 164 additions & 0 deletions firmware/keyboards/bluehand/keymaps/sound_led/keymap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
Copyright 2018 <Pierre Constantineau>
3-Clause BSD License
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "keymap.h"

/*
Sample keymap for demonstrating sound output and LED control.
In order to use sound in other keymaps, add the following to keymap.h:
#define ENABLE_AUDIO
#include "BlueMicro_tone.h"
extern BlueMicro_tone speaker;
SPEAKER_PIN must also be defined in hardware_config.h For bluehand the pin is 45:
#define SPEAKER_PIN 45
For LED control, LED pins should be defined in hardware_config.h, For bluehand those pins are:
#define LED_G 42 //Green
#define LED_R 36 //Red
As a one time setup, enable the LED pins for output:
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
Then turned on with
digitalWrite(LED_G, HIGH);
and off with
digitalWrite(LED_G, LOW);
*/

std::array<std::array<Key, MATRIX_COLS>, MATRIX_ROWS> matrix =
{{
MC0, MC1, MC2, MC3,
MC4, MC5, MC6, MC7
}};


void setupKeymap() {
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
}

void process_user_macros(uint16_t macroid) {
digitalWrite(LED_G, LOW);
digitalWrite(LED_R, LOW);

switch(macroid) {
case MC0:
digitalWrite(LED_G, HIGH);
speaker.playTone(TONE_STARTUP);
speaker.playAllQueuedTonesNow();
break;
case MC1:
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_A4, EIGHTH_TRIPLE, true);
speaker.playNoteNow(NOTE_B4, EIGHTH_TRIPLE);
speaker.playNoteNow(NOTE_D5, EIGHTH_TRIPLE, true);
speaker.playNoteNow(NOTE_B4, EIGHTH_TRIPLE);
speaker.playNoteNow(NOTE_FS5, QUARTER);
speaker.playNoteNow(NOTE_FS5, QUARTER);
speaker.playNoteNow(NOTE_E5, EIGHTH);
break;
case MC2:
digitalWrite(LED_G, HIGH);
speaker.playNoteNow(NOTE_A4, HALF);
break;
case MC3:
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_A4, SIXTEENTH);
break;
case MC4:
// Play a little charge melody, from:
// https://en.wikipedia.org/wiki/Charge_(fanfare)
speaker.playNoteNow(NOTE_G4, EIGHTH_TRIPLE, true);
speaker.playNoteNow(NOTE_C5, EIGHTH_TRIPLE, true);
speaker.playNoteNow(NOTE_E5, EIGHTH_TRIPLE, false);
speaker.playNoteNow(NOTE_G5, EIGHTH, true);
speaker.playNoteNow(NOTE_E5, SIXTEENTH, false);
speaker.playNoteNow(NOTE_G5, HALF, false);
break;
case MC5:
digitalWrite(LED_G, HIGH);
speaker.playNoteNow(NOTE_G5, QUARTER, true);
digitalWrite(LED_G, LOW);
speaker.playNoteNow(NOTE_FS5, EIGHTH);
digitalWrite(LED_G, HIGH);
speaker.playNoteNow(NOTE_G5, QUARTER, true);
digitalWrite(LED_G, LOW);
speaker.playNoteNow(NOTE_D5, EIGHTH);
digitalWrite(LED_G, HIGH);
speaker.playNoteNow(NOTE_E5, EIGHTH_TRIPLE);
digitalWrite(LED_G, LOW);
speaker.playNoteNow(NOTE_E5, EIGHTH_TRIPLE);
break;
case MC6:
digitalWrite(LED_G, HIGH);
digitalWrite(LED_R, HIGH);
break;
case MC7:
// Play happy birthday tune, from:
// http://www.irish-folk-songs.com/happy-birthday-tin-whistle-sheet-music.html#.WXFJMtPytBw
digitalWrite(LED_G, HIGH);
speaker.playNoteNow(NOTE_D4, EIGHTH, true);
speaker.playNoteNow(NOTE_D4, EIGHTH);
digitalWrite(LED_G, LOW);
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_E4, QUARTER); // Bar 1
speaker.playNoteNow(NOTE_D4, QUARTER);
speaker.playNoteNow(NOTE_G4, QUARTER);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_R, LOW);
speaker.playNoteNow(NOTE_FS4, HALF); // Bar 2
speaker.playNoteNow(NOTE_D4, EIGHTH, true);
speaker.playNoteNow(NOTE_D4, EIGHTH);
digitalWrite(LED_G, LOW);
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_E4, QUARTER); // Bar 3
speaker.playNoteNow(NOTE_D4, QUARTER);
speaker.playNoteNow(NOTE_A4, QUARTER);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_R, LOW);
speaker.playNoteNow(NOTE_G4, HALF); // Bar 4
speaker.playNoteNow(NOTE_D4, EIGHTH, true);
speaker.playNoteNow(NOTE_D4, EIGHTH);
digitalWrite(LED_G, LOW);
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_D5, QUARTER); // Bar 5
speaker.playNoteNow(NOTE_B4, QUARTER);
speaker.playNoteNow(NOTE_G4, QUARTER);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_R, LOW);
speaker.playNoteNow(NOTE_FS4, QUARTER); // Bar 6
speaker.playNoteNow(NOTE_E4, QUARTER);
speaker.playNoteNow(NOTE_C5, EIGHTH, true);
speaker.playNoteNow(NOTE_C5, EIGHTH);
digitalWrite(LED_G, LOW);
digitalWrite(LED_R, HIGH);
speaker.playNoteNow(NOTE_B4, QUARTER); // Bar 7
speaker.playNoteNow(NOTE_G4, QUARTER);
speaker.playNoteNow(NOTE_A4, QUARTER);
digitalWrite(LED_G, HIGH);
digitalWrite(LED_R, LOW);
speaker.playNoteNow(NOTE_G4, HALF); // Bar 8
digitalWrite(LED_G, LOW);
break;
}

}

53 changes: 53 additions & 0 deletions firmware/keyboards/bluehand/keymaps/sound_led/keymap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2018 <Pierre Constantineau>
3-Clause BSD License
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "hid_keycodes.h"
#include "keyboard_config.h"
#include "advanced_keycodes.h"
#include "Key.h"
#include <array>
#ifndef KEYMAP_H
#define KEYMAP_H
#define ENABLE_AUDIO
#include "BlueMicro_tone.h"
extern BlueMicro_tone speaker;

#define KC_CAP_D MOD(MOD_LSHIFT, KC_D)
#define NUM_LAYERS 1

#define _L0 0

#define MC0 MC(KC_0)
#define MC1 MC(KC_1)
#define MC2 MC(KC_2)
#define MC3 MC(KC_3)
#define MC4 MC(KC_4)
#define MC5 MC(KC_5)
#define MC6 MC(KC_6)
#define MC7 MC(KC_7)

void setupKeymap();
extern std::array<std::array<Key, MATRIX_COLS>, MATRIX_ROWS> matrix;

#define USER_MACRO_FUNCTION 0
void process_user_macros(uint16_t macroid);
extern void addStringToQueue(const char* str);

#endif /* KEYMAP_H */

0 comments on commit a37115e

Please sign in to comment.