Skip to content

Commit e248892

Browse files
committed
cleaning up
1 parent 003f908 commit e248892

File tree

3 files changed

+199
-1
lines changed

3 files changed

+199
-1
lines changed

Code/CocoMake7_TouchKeyboard_ONE_velocity_space_RENAMED/CocoMake7_TouchKeyboard_ONE_velocity_space_RENAMED.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MIDIMessage midimsg;
1010
#endif
1111

1212
#include <CocoTouch.h>
13-
#include <CocoTouchFilterSettingDefault.h>
13+
#include "CocoTouchFilterSetting.h"
1414

1515
//char key[] = {'C','O','C','O','M','A','K','E','7',' ','O','N','E','!',' '};
1616
char key[] = {' '};
@@ -161,3 +161,4 @@ void loop()
161161
prevVelocity[0] = velocityValue[0];
162162

163163
}
164+
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#define USE_MIDI
2+
#define USE_VELO
3+
4+
#ifdef USE_MIDI
5+
#include <CocoMidi.h>
6+
MIDIMessage midimsg;
7+
#endif
8+
9+
#ifdef USE_KEYBOARD
10+
#include <CocoKeyboard.h>
11+
#endif
12+
13+
14+
#include <CocoTouch.h>
15+
#include "CocoTouchFilterSetting.h"
16+
17+
char key[] = {'C','O','C','O','M','A','K','E','7',' ','O','N','E','!',' '};
18+
19+
//TeenyTouchDusjagr test2;
20+
// ATMEL ATTINY85
21+
//
22+
// +-\/-+
23+
// PB5 1| |8 VCC
24+
//ref ADC3/PB3 2| |7 PB2/ADC1
25+
//capsens ADC2/PB4 3| |6 PB1*
26+
// GND 4| |5 PB0*
27+
// +----+
28+
//
29+
// * indicates PWM port
30+
//
31+
32+
int value[8] = {0,0,0,0,0,0,0,0};
33+
34+
#ifdef USE_VELO
35+
int prevValue[8] = {0,0,0,0,0,0,0,0};
36+
int velocityValue[8] = {0,0,0,0,0,0,0,0};
37+
#endif
38+
39+
uint8_t note_off[8] = {1,1,1,1,1,1,1,1};
40+
uint16_t offset_adc[8] = {0,0,0,0,0,0,0,0};
41+
42+
//filter settings
43+
44+
CocoTouchFilterSetting CocoFilter[8];
45+
int filtered_value = 0;
46+
uint8_t pin_queue = 0;
47+
uint8_t multiplexer_mapping[8] = {6,7,4,4,3,0,1,2}; //remap multiplexer pin
48+
unsigned long previousMillis = 0; // will store last time LED was updated
49+
int keyCount = -1;
50+
int keyTotal = 15;
51+
int ledPin = PB0;
52+
53+
#define PIN_SELECT 0
54+
#define NUM_CHANNEL 3
55+
56+
#define ADC_REF_PIN PB2
57+
#define ADC_SENSE_PIN PB4
58+
59+
60+
void usb_poll()
61+
{
62+
usbPoll();
63+
}
64+
65+
void setup()
66+
{
67+
68+
#ifdef USE_MIDI
69+
CocoMidi.init();
70+
#endif
71+
72+
#ifdef USE_KEYBOARD
73+
CocoKeyboard.update();
74+
#endif
75+
76+
77+
CocoTouch.begin();
78+
CocoTouch.setAdcSpeed(4);
79+
CocoTouch.delay = 4;
80+
//TeenyTouchDusjagr.delay_cb = &delay;
81+
CocoTouch.usb_poll = &usb_poll;
82+
83+
offset_adc[0] = CocoTouch.sense(ADC_SENSE_PIN,ADC_REF_PIN, 8 );
84+
//offset_adc[0] = 0;
85+
86+
#ifdef USE_MIDI
87+
CocoMidi.delay(100);
88+
#endif
89+
pinMode(ledPin, OUTPUT);
90+
digitalWrite(ledPin, HIGH);
91+
CocoMidi.delay(100);
92+
digitalWrite(ledPin, LOW);
93+
CocoMidi.delay(100);
94+
digitalWrite(ledPin, HIGH);
95+
CocoMidi.delay(100);
96+
digitalWrite(ledPin, LOW);
97+
CocoMidi.delay(100);
98+
99+
}
100+
101+
void loop()
102+
{
103+
104+
if (millis()-previousMillis >= 5) // 0% data loss
105+
{
106+
//CocoMidi.sendCCHires(value, 1);
107+
filtered_value = CocoTouchFilter_get(&CocoFilter[0]);
108+
velocityValue[0] = filtered_value - prevValue[0];
109+
prevValue[0] = filtered_value;
110+
if (filtered_value <= 30)
111+
{digitalWrite(ledPin, LOW);}
112+
if (filtered_value >= 100)
113+
{digitalWrite(ledPin, HIGH);}
114+
if (filtered_value <= 0)
115+
{filtered_value = 0;}
116+
if (filtered_value >= 1023)
117+
{filtered_value = 1023;
118+
digitalWrite(ledPin, HIGH);
119+
}
120+
121+
//CocoMidi.send(MIDI_NOTEON,0, filtered_value);
122+
CocoMidi.sendCCHires(filtered_value, (4*1)+1);
123+
CocoMidi.sendCCHires(velocityValue[0]+500, (4*0)+1);
124+
CocoMidi.sendCCHires(value[0], (4*2)+1);
125+
126+
if (filtered_value >= 10)
127+
{
128+
if (note_off[0] == 1)
129+
{
130+
#ifdef USE_MIDI
131+
// CocoMidi.send(MIDI_NOTEON,0, filtered_value );
132+
#endif
133+
#ifdef USE_KEYBOARD
134+
keyCount++;
135+
if (keyCount == keyTotal){keyCount = 0;}
136+
digitalWrite(ledPin, HIGH);
137+
138+
CocoKeyboard.print(key[keyCount]);
139+
#endif
140+
note_off[0] = 0;
141+
}
142+
}
143+
else
144+
{ digitalWrite(ledPin, LOW);
145+
146+
if (note_off[0] == 0)
147+
{
148+
#ifdef USE_MIDI
149+
//CocoMidi.send(MIDI_NOTEOFF,0,127);
150+
#endif
151+
note_off[0] = 1;
152+
}
153+
}
154+
155+
previousMillis = millis();
156+
}
157+
158+
159+
value[0] = CocoTouch.sense(ADC_SENSE_PIN,ADC_REF_PIN, 7 ) - offset_adc[0];
160+
if (value[0] > 0) CocoTouchFilter_put(&CocoFilter[0], value[0]);
161+
162+
#ifdef USE_MIDI
163+
CocoMidi.update();
164+
#endif
165+
166+
#ifdef USE_MIDI
167+
CocoMidi.delay(1);
168+
#endif
169+
170+
#ifdef USE_KEYBOARD
171+
//CocoKeyboard.update();
172+
CocoKeyboard.delay(1);
173+
#endif
174+
175+
//velocityValue[0] = value[0]-prevValue[0];
176+
//prevValue[0] = value[0];
177+
}
178+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
#define SAMPLEFILTER_TAP_NUM 10
4+
5+
static int filter_taps[SAMPLEFILTER_TAP_NUM] = {
6+
8,
7+
39,
8+
97,
9+
168,
10+
217,
11+
217,
12+
168,
13+
97,
14+
39,
15+
8
16+
};
17+
18+
19+
#include "CocoTouchFilter.h"

0 commit comments

Comments
 (0)