MIDI-out and MCP23017 sketch

This commit is contained in:
Lukas
2013-02-13 20:05:54 +01:00
parent 5c4627d257
commit 4fabe518b0
6 changed files with 204 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
/*
Morse.cpp - Library for flashing Morse code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#include "Arduino.h"
#include "input_4051.h"
const int tolerance = 4;
input_4051::input_4051(int analogPin, int s0Pin, int s1Pin, int s2Pin, void (*valueChangeCallback(int,int)))
{
_analog = analogPin;
_s0 = s0Pin;
_s1 = s1Pin;
_s2 = s2Pin;
pinMode(_analog,INPUT);
pinMode(_s0,OUTPUT);
pinMode(_s1,OUTPUT);
pinMode(_s2,OUTPUT);
_valueChangeCallback = valueChangeCallback;
_value = {-1,-1,-1,-1,-1,-1,-1,-1};
}
void input_4051::loop()
{
for (count=0; count<=7; count++) {
r0 = bitRead(count,0);
r1 = bitRead(count,1);
r2 = bitRead(count,2);
digitalWrite(_s0, r0);
digitalWrite(_s1, r1);
digitalWrite(_s2, r2);
int read = analogRead(_analog);
if (value[count] < read - tolerance || value[count] > read + tolerance) {
value[count] = read;
_valueChangeCallback(count, read);
}
}
}
+28
View File
@@ -0,0 +1,28 @@
/*
input_4051.h - Library for reading inputs from 4051 multiplexer
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#ifndef input_4051_h
#define input_4051_h
#include "Arduino.h"
class input_4051
{
public:
Morse(int analogPin, int s0Pin, int s1Pin, int s2Pin, void (*valueChangeCallback(int,int)));
void loop(void);
int getSpecificValue(int pin);
private:
int _analog;
int _s0;
int _s1;
int _s2;
void (*_valueChangeCallback(int,int);
int _value[8];
};
#endif