master
Slayr 5 years ago
commit 3b7995f3fd

@ -0,0 +1,59 @@
#include <CapacitiveSensor.h>
/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10M between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of foil/metal on this pin
*/
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_4_3 = CapacitiveSensor(4,3); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long valCons1 = constrain(total1, 10000, 225000);
long mappedVal1 = map(valCons1, 10000, 225000, 0, 1024);
long total2 = cs_4_3.capacitiveSensor(30);
long valCons2 = constrain(total2, 10000, 225000);
long mappedVal2 = map(valCons2, 10000, 225000, 0, 1024);
long total3 = cs_4_5.capacitiveSensor(30);
long valCons3 = constrain(total3, 10000, 225000);
long mappedVal3 = map(valCons3, 10000, 225000, 0, 1024);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.print(total1); // print sensor output 1
Serial.print("\t");
Serial.print(total2); // print sensor output 2
Serial.print("\t");
Serial.println(total3); // print sensor output 3
Serial.print(valCons1);
Serial.print("\t");
Serial.print(valCons2);
Serial.print("\t");
Serial.println(valCons3);
Serial.print(mappedVal1);
Serial.print("\t");
Serial.print(mappedVal2);
Serial.print("\t");
Serial.println(mappedVal3);
delay(300); // arbitrary delay to limit data to serial port
}

@ -0,0 +1,189 @@
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
int LEDPin1 = 38;
int LEDPin2 = 39;
int LEDPin3 = 40;
int LEDPin5 = 41;
int LEDPin4 = 42;
int LEDPin6 = 43;
int LEDPin7 = 44;
int LEDPin8 = 45;
int LEDPin9 = 46;
int LEDPin10 = 47;
int LEDPin11 = 48;
int LEDPin12 = 49;
int LEDPin13 = 50;
int LEDPin14 = 51;
int LEDPin15 = 52;
int LEDPin16 = 53;
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
pinMode(LEDPin4, OUTPUT);
pinMode(LEDPin5, OUTPUT);
pinMode(LEDPin6, OUTPUT);
pinMode(LEDPin7, OUTPUT);
pinMode(LEDPin8, OUTPUT);
pinMode(LEDPin9, OUTPUT);
pinMode(LEDPin10, OUTPUT);
pinMode(LEDPin11, OUTPUT);
pinMode(LEDPin12, OUTPUT);
pinMode(LEDPin13, OUTPUT);
pinMode(LEDPin14, OUTPUT);
pinMode(LEDPin15, OUTPUT);
pinMode(LEDPin16, OUTPUT);
digitalWrite(LEDPin1, LOW);
digitalWrite(LEDPin2, LOW);
digitalWrite(LEDPin3, LOW);
digitalWrite(LEDPin4, LOW);
digitalWrite(LEDPin5, LOW);
digitalWrite(LEDPin6, LOW);
digitalWrite(LEDPin7, LOW);
digitalWrite(LEDPin8, LOW);
digitalWrite(LEDPin9, LOW);
digitalWrite(LEDPin10, LOW);
digitalWrite(LEDPin11, LOW);
digitalWrite(LEDPin12, LOW);
digitalWrite(LEDPin13, LOW);
digitalWrite(LEDPin14, LOW);
digitalWrite(LEDPin15, LOW);
digitalWrite(LEDPin16, LOW);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long valCons = constrain(total1, 10000, 280000);
long mappedVal = map(valCons, 10000, 280000, 0, 1024);
if (mappedVal >200) {
digitalWrite(LEDPin1, HIGH);
}
else {
digitalWrite(LEDPin1, LOW);
}
if (mappedVal >345) {
digitalWrite(LEDPin2, HIGH);
}
else {
digitalWrite(LEDPin2, LOW);
}
if (mappedVal >400) {
digitalWrite(LEDPin3, HIGH);
}
else {
digitalWrite(LEDPin3, LOW);
}
if (mappedVal >367) {
digitalWrite(LEDPin4, HIGH);
}
else {
digitalWrite(LEDPin4, LOW);
}
if (mappedVal >993) {
digitalWrite(LEDPin5, HIGH);
}
else {
digitalWrite(LEDPin5, LOW);
}
if (mappedVal >398) {
digitalWrite(LEDPin6, HIGH);
}
else {
digitalWrite(LEDPin6, LOW);
}
if (mappedVal >912) {
digitalWrite(LEDPin7, HIGH);
}
else {
digitalWrite(LEDPin7, LOW);
}
if (mappedVal >800) {
digitalWrite(LEDPin8, HIGH);
}
else {
digitalWrite(LEDPin8, LOW);
}
if (mappedVal >622) {
digitalWrite(LEDPin9, HIGH);
}
else {
digitalWrite(LEDPin9, LOW);
}
if (mappedVal >22) {
digitalWrite(LEDPin10, HIGH);
}
else {
digitalWrite(LEDPin10, LOW);
}
if (mappedVal >114) {
digitalWrite(LEDPin11, HIGH);
}
else {
digitalWrite(LEDPin11, LOW);
}
if (mappedVal >112) {
digitalWrite(LEDPin12, HIGH);
}
else {
digitalWrite(LEDPin12, LOW);
}
if (mappedVal >313) {
digitalWrite(LEDPin13, HIGH);
}
else {
digitalWrite(LEDPin13, LOW);
}
if (mappedVal >214) {
digitalWrite(LEDPin14, HIGH);
}
else {
digitalWrite(LEDPin14, LOW);
}
if (mappedVal >315) {
digitalWrite(LEDPin15, HIGH);
}
else {
digitalWrite(LEDPin15, LOW);
}
if (mappedVal >100) {
digitalWrite(LEDPin16, HIGH);
}
else {
digitalWrite(LEDPin16, LOW);
}
Serial.print(total1);
Serial.print("\t");
Serial.print(valCons);
Serial.print("\t");
Serial.println(mappedVal); // print sensor output 1
delay(100); // arbitrary delay to limit data to serial port
}

@ -0,0 +1,225 @@
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
int LEDPin1 = 38;
int LEDPin2 = 39;
int LEDPin3 = 40;
int LEDPin5 = 41;
int LEDPin4 = 42;
int LEDPin6 = 43;
int LEDPin7 = 44;
int LEDPin8 = 45;
int LEDPin9 = 46;
int LEDPin10 = 47;
int LEDPin11 = 48;
int LEDPin12 = 49;
int LEDPin13 = 50;
int LEDPin14 = 51;
int LEDPin15 = 52;
int LEDPin16 = 53;
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
pinMode(LEDPin4, OUTPUT);
pinMode(LEDPin5, OUTPUT);
pinMode(LEDPin6, OUTPUT);
pinMode(LEDPin7, OUTPUT);
pinMode(LEDPin8, OUTPUT);
pinMode(LEDPin9, OUTPUT);
pinMode(LEDPin10, OUTPUT);
pinMode(LEDPin11, OUTPUT);
pinMode(LEDPin12, OUTPUT);
pinMode(LEDPin13, OUTPUT);
pinMode(LEDPin14, OUTPUT);
pinMode(LEDPin15, OUTPUT);
pinMode(LEDPin16, OUTPUT);
digitalWrite(LEDPin1, LOW);
digitalWrite(LEDPin2, LOW);
digitalWrite(LEDPin3, LOW);
digitalWrite(LEDPin4, LOW);
digitalWrite(LEDPin5, LOW);
digitalWrite(LEDPin6, LOW);
digitalWrite(LEDPin7, LOW);
digitalWrite(LEDPin8, LOW);
digitalWrite(LEDPin9, LOW);
digitalWrite(LEDPin10, LOW);
digitalWrite(LEDPin11, LOW);
digitalWrite(LEDPin12, LOW);
digitalWrite(LEDPin13, LOW);
digitalWrite(LEDPin14, LOW);
digitalWrite(LEDPin15, LOW);
digitalWrite(LEDPin16, LOW);
}
void loop()
{
long start = millis();
long rawSensor = cs_4_2.capacitiveSensor(30);
constrain(rawSensor, 0, 30000);
int drawingSensor = map(rawSensor, 0, 30000, 0, 950);
if (drawingSensor >200) {
digitalWrite(LEDPin1, HIGH);
delay(10);
digitalWrite(LEDPin1, LOW);
}
else {
digitalWrite(LEDPin1, LOW);
}
if (drawingSensor >345) {
digitalWrite(LEDPin2, HIGH);
delay(10);
digitalWrite(LEDPin2, LOW);
}
else {
digitalWrite(LEDPin2, LOW);
}
if (drawingSensor >543) {
digitalWrite(LEDPin3, HIGH);
delay(30);
digitalWrite(LEDPin3, LOW);
}
else {
digitalWrite(LEDPin3, LOW);
}
if (drawingSensor >467) {
digitalWrite(LEDPin4, HIGH);
delay(15);
digitalWrite(LEDPin4, LOW);
}
else {
digitalWrite(LEDPin4, LOW);
}
if (drawingSensor >793) {
digitalWrite(LEDPin5, HIGH);
delay(20);
digitalWrite(LEDPin5, LOW);
}
else {
digitalWrite(LEDPin5, LOW);
}
if (drawingSensor >398) {
digitalWrite(LEDPin6, HIGH);
delay(10);
digitalWrite(LEDPin6, LOW);
}
else {
digitalWrite(LEDPin6, LOW);
}
if (drawingSensor >612) {
digitalWrite(LEDPin7, HIGH);
delay(10);
digitalWrite(LEDPin7, LOW);
}
else {
digitalWrite(LEDPin7, LOW);
}
if (drawingSensor >709) {
digitalWrite(LEDPin8, HIGH);
delay(10);
digitalWrite(LEDPin8, LOW);
}
else {
digitalWrite(LEDPin8, LOW);
}
if (drawingSensor >622) {
digitalWrite(LEDPin9, HIGH);
delay(10);
digitalWrite(LEDPin9, LOW);
}
else {
digitalWrite(LEDPin9, LOW);
}
if (drawingSensor >22) {
digitalWrite(LEDPin10, HIGH);
delay(10);
digitalWrite(LEDPin10, LOW);
}
else {
digitalWrite(LEDPin10, LOW);
}
if (drawingSensor >114) {
digitalWrite(LEDPin11, HIGH);
delay(10);
digitalWrite(LEDPin11, LOW);
}
else {
digitalWrite(LEDPin11, LOW);
}
if (drawingSensor >712) {
digitalWrite(LEDPin12, HIGH);
delay(10);
digitalWrite(LEDPin12, LOW);
}
else {
digitalWrite(LEDPin12, LOW);
}
if (drawingSensor >313) {
digitalWrite(LEDPin13, HIGH);
delay(10);
digitalWrite(LEDPin13, LOW);
}
else {
digitalWrite(LEDPin13, LOW);
}
if (drawingSensor >814) {
digitalWrite(LEDPin14, HIGH);
delay(10);
digitalWrite(LEDPin14, LOW);
}
else {
digitalWrite(LEDPin14, LOW);
}
if (drawingSensor >815) {
digitalWrite(LEDPin15, HIGH);
delay(10);
digitalWrite(LEDPin15, LOW);
}
else {
digitalWrite(LEDPin15, LOW);
}
if (drawingSensor >800) {
digitalWrite(LEDPin16, HIGH);
delay(10);
digitalWrite(LEDPin16, LOW);
}
else {
digitalWrite(LEDPin16, LOW);
}
//Serial.print(millis() - start); // check on performance in milliseconds
//Serial.print("\t"); // tab character for debug windown spacing
//Serial.print("Raw Sensor Value ");
//Serial.print("\t");
//Serial.println(rawSensor); // print sensor output 1
Serial.print("Mapped Sensor Value ");
Serial.print("\t");
Serial.println(drawingSensor);
//delay(1000); // arbitrary delay to limit data to serial port
}

@ -0,0 +1,159 @@
#include <CapacitiveSensor.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "sample.h"
#define LED_PIN 13
#define SPEAKER_PIN 11
#define KNOB_1 (0)
#define KNOB_2 (1)
#define KNOB_3 (2)
#define INPUT_3 (3)
volatile uint16_t sample;
volatile uint16_t loop_start;
volatile uint16_t loop_length;
volatile uint16_t index_bounds;
volatile uint16_t loop_overflow;
volatile boolean gate;
volatile boolean gate_prev;
byte lastSample;
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_4_3 = CapacitiveSensor(4,3); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
void startPlayback()
{
pinMode(SPEAKER_PIN, OUTPUT);
// Set up Timer 2 to do pulse width modulation on the speaker pin.
// Use internal clock (datasheet p.160)
ASSR &= ~(_BV(EXCLK) | _BV(AS2));
// Set fast PWM mode (p.157)
TCCR2A |= _BV(WGM21) | _BV(WGM20);
TCCR2B &= ~_BV(WGM22);
// Do non-inverting PWM on pin OC2A (p.155)
// On the Arduino this is pin 11.
TCCR2A = (TCCR2A | _BV(COM2A1)) & ~_BV(COM2A0);
TCCR2A &= ~(_BV(COM2B1) | _BV(COM2B0));
// No prescaler (p.158)
TCCR2B = (TCCR2B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
// Set initial pulse width to the first sample.
OCR2A = pgm_read_byte(&sound_data[0]);
// Set up Timer 1 to send a sample every interrupt.
cli();
// Set CTC mode (Clear Timer on Compare Match) (p.133)
// Have to set OCR1A *after*, otherwise it gets reset to 0!
TCCR1B = (TCCR1B & ~_BV(WGM13)) | _BV(WGM12);
TCCR1A = TCCR1A & ~(_BV(WGM11) | _BV(WGM10));
// No prescaler (p.134)
TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
// Set the compare register (OCR1A).
// OCR1A is a 16-bit register, so we have to do this with
// interrupts disabled to be safe.
OCR1A = F_CPU / SAMPLE_RATE; // 16e6 / 8000 = 2000
// Enable interrupt when TCNT1 == OCR1A (p.136)
TIMSK1 |= _BV(OCIE1A);
lastSample = pgm_read_byte(&sound_data[sound_length - 1]);
sample = 0;
sei();
}
void stopPlayback()
{
TIMSK1 &= ~_BV(OCIE1A); // Disable playback per-sample interrupt.
TCCR1B &= ~_BV(CS10); // Disable the per-sample timer completely.
TCCR2B &= ~_BV(CS10); // Disable the PWM timer.
digitalWrite(SPEAKER_PIN, LOW);
}
void setup()
{
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
startPlayback();
loop_start = 0;
loop_length = sound_length;
gate = false;
gate_prev = false;
}
// This is called at 8000 Hz to load the next sample.
ISR(TIMER1_COMPA_vect)
{
if(sample >= index_bounds)
{
sample = loop_start;
}
else if((sample < loop_start) &&
(sample >= loop_overflow))
{
sample = loop_start;
}
else if((gate == true) &&
(gate_prev == false))
{
sample = loop_start;
}
else
{
OCR2A = pgm_read_byte(&sound_data[sample % sound_length]);
}
gate_prev = gate;
sample++;
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long valCons1 = constrain(total1, 10000, 225000);
long mappedVal1 = map(valCons1, 10000, 225000, 0, 1024);
long total2 = cs_4_3.capacitiveSensor(30);
long valCons2 = constrain(total2, 10000, 225000);
long mappedVal2 = map(valCons2, 10000, 225000, 0, 1024);
long total3 = cs_4_5.capacitiveSensor(30);
long valCons3 = constrain(total3, 10000, 225000);
long mappedVal3 = map(valCons3, 10000, 225000, 0, 1024);
loop_start = mappedVal3 / 1024.0 * sound_length;
loop_length = (mappedVal2 + 1) / 1024.0 * sound_length;
OCR1A = (512.0 / (mappedVal1 + 1)) * (F_CPU / SAMPLE_RATE);
gate = analogRead(3) >> 9; // 10 bits in. gate < 512 == off, gate >= 512 == on
// can be up to 2x sound length. the more you know.
index_bounds = loop_start + loop_length;
// this will set the overflow length. take the loop overflow into account when checking the loop boundaries
if(index_bounds > sound_length)
{
loop_overflow = index_bounds - sound_length;
}
else
{
loop_overflow = 0;
}
}

File diff suppressed because it is too large Load Diff

@ -9,10 +9,10 @@ int toggle_2;
int toggle_1; int toggle_1;
char poetry; char poetry;
char animal1[] = " cat"; char animal1[] = "cat";
char animal2[] = " dog"; char animal2[] = "dog";
char animal3[] = " mouse"; char animal3[] = "mouse";
char animal4[]= " cockroach"; char animal4[]= "cockroach";
char str[] = "hello"; char str[] = "hello";
char str2[] = "CAT"; char str2[] = "CAT";
@ -40,8 +40,8 @@ void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
x=0; x=0;
y=0; y=0;
TV.begin(_NTSC,128,96); TV.begin(_NTSC,120,96);
TV.select_font(font4x6); TV.select_font(font6x8);
} }

Loading…
Cancel
Save