Skip to content

Commit

Permalink
update 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
RyoKosaka committed Jul 19, 2019
1 parent 489d4a0 commit 5988230
Show file tree
Hide file tree
Showing 23 changed files with 6,240 additions and 2,291 deletions.
509 changes: 509 additions & 0 deletions EEPROM_ESP.cpp

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions EEPROM_ESP.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
EEPROM.h -ported by Paolo Becchi to Esp32 from esp8266 EEPROM
-Modified by Elochukwu Ifediora <[email protected]>
-Converted to nvs [email protected]
Uses a nvs byte array to emulate EEPROM
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef EEPROMESP_h
#define EEPROMESP_h
#ifndef EEPROM_FLASH_PARTITION_NAME
#define EEPROM_FLASH_PARTITION_NAME "eeprom"
#endif
#include <Arduino.h>

typedef uint32_t nvs_handle;

class EEPROMClassESP
{
public:
EEPROMClassESP(uint32_t sector);
EEPROMClassESP(const char *name, uint32_t user_defined_size);
EEPROMClassESP(void);
~EEPROMClassESP(void);

bool begin(size_t size);
uint8_t read(int address);
void write(int address, uint8_t val);
uint16_t length();
bool commit();
void end();

uint8_t *getDataPtr();

template <typename T>
T &get(int address, T &t)
{
if (address < 0 || address + sizeof(T) > _size)
return t;

memcpy((uint8_t *)&t, _data + address, sizeof(T));
return t;
}

template <typename T>
const T &put(int address, const T &t)
{
if (address < 0 || address + sizeof(T) > _size)
return t;

memcpy(_data + address, (const uint8_t *)&t, sizeof(T));
_dirty = true;
return t;
}

uint8_t readByte(int address);
int8_t readChar(int address);
uint8_t readUChar(int address);
int16_t readShort(int address);
uint16_t readUShort(int address);
int32_t readInt(int address);
uint32_t readUInt(int address);
int32_t readLong(int address);
uint32_t readULong(int address);
int64_t readLong64(int address);
uint64_t readULong64(int address);
float_t readFloat(int address);
double_t readDouble(int address);
bool readBool(int address);
size_t readString(int address, char *value, size_t maxLen);
String readString(int address);
size_t readBytes(int address, void *value, size_t maxLen);
template <class T>
T readAll(int address, T &);

size_t writeByte(int address, uint8_t value);
size_t writeChar(int address, int8_t value);
size_t writeUChar(int address, uint8_t value);
size_t writeShort(int address, int16_t value);
size_t writeUShort(int address, uint16_t value);
size_t writeInt(int address, int32_t value);
size_t writeUInt(int address, uint32_t value);
size_t writeLong(int address, int32_t value);
size_t writeULong(int address, uint32_t value);
size_t writeLong64(int address, int64_t value);
size_t writeULong64(int address, uint64_t value);
size_t writeFloat(int address, float_t value);
size_t writeDouble(int address, double_t value);
size_t writeBool(int address, bool value);
size_t writeString(int address, const char *value);
size_t writeString(int address, String value);
size_t writeBytes(int address, const void *value, size_t len);
template <class T>
T writeAll(int address, const T &);

protected:
nvs_handle _handle;
uint8_t *_data;
size_t _size;
bool _dirty;
const char *_name;
uint32_t _user_defined_size;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
extern EEPROMClassESP EEPROM_ESP;
#endif

#endif
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HelloDrum-arduino-Library
This is a library for making E-Drum with Arduino.
**Ver.0.6(6/18/2019) Work in progress.**
**Ver.0.7(7/20/2019) Work in progress.**

## Description

Expand All @@ -13,7 +13,7 @@ Use at your own risk.

## Features

- Single piezo pad, ~~Dual Piezo pad~~, 2 zone cymbal, 3 zone cymbal
- Single piezo pad, Dual Piezo pad, 2 zone cymbal, 3 zone cymbal
- It is compatible with YAMAHA's 3 zone cymbal.(PCY135/PCY155)
- Sensitivity, Threshold, Scan Time, Mask Time, Note Number can be set with each piezo.
- Both optical(TCRT5000) and FSR type hi-hat controllers can be used.
Expand All @@ -32,10 +32,10 @@ Use at your own risk.

//Setting
int SNARE[5] = {
800, //sensitivity
20, //threshold
5, //scantime
10, //masktime
80, //sensitivity
10, //threshold
20, //scantime
20, //masktime
38 //note
};

Expand Down Expand Up @@ -72,10 +72,10 @@ Use at your own risk.

//Setting
int SNARE[5] = {
800, //sensitivity
20, //threshold
5, //scantime
10, //masktime
80, //sensitivity
10, //threshold
20, //scantime
20, //masktime
38 //note
};

Expand Down Expand Up @@ -136,6 +136,12 @@ The STL data of pads from 6 inches to 12 inches.(<https://www.thingiverse.com/Ry

## Release History

* 0.7
- Improved sensing
- Dual Piezo sensing available (Test)
- ESP32 EEPROM available
- Setting mode with I2C LCD or I2C OLED available
- Add sample code
* 0.6
- Sensing with MUX(4051) is available
- Add BLE MIDI sample code with ESP32
Expand Down Expand Up @@ -163,4 +169,4 @@ The STL data of pads from 6 inches to 12 inches.(<https://www.thingiverse.com/Ry

## Licence

[MIT](http://opensource.org/licenses/mit-license.php)
[MIT](http://opensource.org/licenses/mit-license.php)
36 changes: 22 additions & 14 deletions examples/InitializeEEPROM/InitializeEEPROM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
The values after initialization are as follows.
Sensitivity = 80
Threshold = 20
Scan Time = 5
Sensitivity = 100
Threshold = 10
Scan Time = 30
Mask Time = 10
Note = 38
Note of rim/Edge = 39
Expand All @@ -19,17 +19,15 @@
https://open-e-drums.tumblr.com/
*/


#include <hellodrum.h>

//input number
HelloDrum pad_0(0);
HelloDrum pad_1(1);
HelloDrum pad_2(2);
HelloDrum pad_3(3);
HelloDrum pad_4(4);
HelloDrum pad_5(5);
//if you use arduino MEGA, uncomment below lines.
/*
HelloDrum pad_6(6);
HelloDrum pad_7(7);
HelloDrum pad_8(8);
Expand All @@ -40,19 +38,25 @@ HelloDrum pad_12(12);
HelloDrum pad_13(13);
HelloDrum pad_14(14);
HelloDrum pad_15(15);
*/

void setup() {

//if you have more pads, just add code like this
//HelloDrum pad_16(16);
//HelloDrum pad_17(17);
//HelloDrum pad_18(18);

void setup()
{

//if you use ESP32, uncomment below line.
//EEPROM_ESP.begin(512);

//Initialize
pad_0.initMemory();
pad_1.initMemory();
pad_2.initMemory();
pad_3.initMemory();
pad_4.initMemory();
pad_5.initMemory();
//if you use arduino MEGA, uncomment below lines.
/*
pad_6.initMemory();
pad_7.initMemory();
pad_8.initMemory();
Expand All @@ -63,9 +67,13 @@ void setup() {
pad_13.initMemory();
pad_14.initMemory();
pad_15.initMemory();
*/
}

void loop() {
//if you have more pads, just add code like this
//pad_16.initMemory();
//pad_17.initMemory();
//pad_18.initMemory();
}

void loop()
{
}
50 changes: 26 additions & 24 deletions examples/SimpleSensing/SimpleSensing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
*/

/////////////////////////////// INITIAL VALUE ///////////////////////////////////
/////////////////////////////// SETTING VALUE ///////////////////////////////////

//Determine the initial value.
//Determine the setting value.
//By changing the number in this array you can set sensitivity, threshold and so on.

int SNARE[5] = {
800, //sensitivity
20, //threshold
5, //scan time
10, //mask time
38 //note
};
100, //sensitivity (1-100)
10, //threshold (1-100)
30, //scan time (1-)
10, //mask time (1-)
38 //note (0-127)
};

int TOM[5] = {
800, //sensitivity
20, //threshold
5, //scan time
10, //mask time
50 //note
100, //sensitivity (1-100)
10, //threshold (1-100)
30, //scan time (1-)
10, //mask time(1-)
50 //note (0-127)
};

/////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -45,32 +45,34 @@ MIDI_CREATE_DEFAULT_INSTANCE();
HelloDrum snare(0);
HelloDrum tom(1);

void setup() {
void setup()
{
//If you use Hairless MIDI, you have to comment out the next line.
//MIDI.begin(10);
MIDI.begin(10);

//And uncomment the next two lines.
MIDI.begin();
Serial.begin(38400);
//MIDI.begin();
//Serial.begin(38400);
}

void loop() {

void loop()
{
//Piezo sensing is done in this line. And it is returned as a velocity of 127 stages.
//For each piezo, one line is required.
snare.singlePiezo(SNARE[0], SNARE[1], SNARE[2], SNARE[3]);
tom.singlePiezo(TOM[0], TOM[1], TOM[2], TOM[3]);

//MIDI signals are transmitted with this IF statement.
//For each piezo, one IF statement is required
if (snare.hit == true) {
MIDI.sendNoteOn(SNARE[4], snare.velocity, 10); //(note, velocity, channel)
if (snare.hit == true)
{
MIDI.sendNoteOn(SNARE[4], snare.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(SNARE[4], 0, 10);
}

if (tom.hit == true) {
MIDI.sendNoteOn(TOM[4], tom.velocity, 10); //(note, velocity, channel)
if (tom.hit == true)
{
MIDI.sendNoteOn(TOM[4], tom.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(TOM[4], 0, 10);
}

}
Loading

0 comments on commit 5988230

Please sign in to comment.