A simple touch sensor that sends a message to computer when it notices touch. I'm using a simple voltage divider with 10k resistor and body impedance.

Dependencies:   mbed

Committer:
Vekotin
Date:
Thu Jan 30 06:13:55 2014 +0000
Revision:
1:7ed7d128d225
egw

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vekotin 1:7ed7d128d225 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Vekotin 1:7ed7d128d225 2 *
Vekotin 1:7ed7d128d225 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Vekotin 1:7ed7d128d225 4 * and associated documentation files (the "Software"), to deal in the Software without
Vekotin 1:7ed7d128d225 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Vekotin 1:7ed7d128d225 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Vekotin 1:7ed7d128d225 7 * Software is furnished to do so, subject to the following conditions:
Vekotin 1:7ed7d128d225 8 *
Vekotin 1:7ed7d128d225 9 * The above copyright notice and this permission notice shall be included in all copies or
Vekotin 1:7ed7d128d225 10 * substantial portions of the Software.
Vekotin 1:7ed7d128d225 11 *
Vekotin 1:7ed7d128d225 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Vekotin 1:7ed7d128d225 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Vekotin 1:7ed7d128d225 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Vekotin 1:7ed7d128d225 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Vekotin 1:7ed7d128d225 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Vekotin 1:7ed7d128d225 17 */
Vekotin 1:7ed7d128d225 18
Vekotin 1:7ed7d128d225 19 #ifndef USBMIDI_H
Vekotin 1:7ed7d128d225 20 #define USBMIDI_H
Vekotin 1:7ed7d128d225 21
Vekotin 1:7ed7d128d225 22 /* These headers are included for child class. */
Vekotin 1:7ed7d128d225 23 #include "USBEndpoints.h"
Vekotin 1:7ed7d128d225 24 #include "USBDescriptor.h"
Vekotin 1:7ed7d128d225 25 #include "USBDevice_Types.h"
Vekotin 1:7ed7d128d225 26
Vekotin 1:7ed7d128d225 27 #include "USBDevice.h"
Vekotin 1:7ed7d128d225 28 #include "MIDIMessage.h"
Vekotin 1:7ed7d128d225 29
Vekotin 1:7ed7d128d225 30 #define DEFAULT_CONFIGURATION (1)
Vekotin 1:7ed7d128d225 31
Vekotin 1:7ed7d128d225 32 /**
Vekotin 1:7ed7d128d225 33 * USBMIDI example
Vekotin 1:7ed7d128d225 34 *
Vekotin 1:7ed7d128d225 35 * @code
Vekotin 1:7ed7d128d225 36 * #include "mbed.h"
Vekotin 1:7ed7d128d225 37 * #include "USBMIDI.h"
Vekotin 1:7ed7d128d225 38 *
Vekotin 1:7ed7d128d225 39 * USBMIDI midi;
Vekotin 1:7ed7d128d225 40 *
Vekotin 1:7ed7d128d225 41 * int main() {
Vekotin 1:7ed7d128d225 42 * while (1) {
Vekotin 1:7ed7d128d225 43 * for(int i=48; i<83; i++) { // send some messages!
Vekotin 1:7ed7d128d225 44 * midi.write(MIDIMessage::NoteOn(i));
Vekotin 1:7ed7d128d225 45 * wait(0.25);
Vekotin 1:7ed7d128d225 46 * midi.write(MIDIMessage::NoteOff(i));
Vekotin 1:7ed7d128d225 47 * wait(0.5);
Vekotin 1:7ed7d128d225 48 * }
Vekotin 1:7ed7d128d225 49 * }
Vekotin 1:7ed7d128d225 50 * }
Vekotin 1:7ed7d128d225 51 * @endcode
Vekotin 1:7ed7d128d225 52 */
Vekotin 1:7ed7d128d225 53 class USBMIDI: public USBDevice {
Vekotin 1:7ed7d128d225 54 public:
Vekotin 1:7ed7d128d225 55
Vekotin 1:7ed7d128d225 56 /**
Vekotin 1:7ed7d128d225 57 * Constructor
Vekotin 1:7ed7d128d225 58 *
Vekotin 1:7ed7d128d225 59 * @param vendor_id Your vendor_id
Vekotin 1:7ed7d128d225 60 * @param product_id Your product_id
Vekotin 1:7ed7d128d225 61 * @param product_release Your preoduct_release
Vekotin 1:7ed7d128d225 62 */
Vekotin 1:7ed7d128d225 63 USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001);
Vekotin 1:7ed7d128d225 64
Vekotin 1:7ed7d128d225 65 /**
Vekotin 1:7ed7d128d225 66 * Send a MIDIMessage
Vekotin 1:7ed7d128d225 67 *
Vekotin 1:7ed7d128d225 68 * @param m The MIDIMessage to send
Vekotin 1:7ed7d128d225 69 */
Vekotin 1:7ed7d128d225 70 void write(MIDIMessage m);
Vekotin 1:7ed7d128d225 71
Vekotin 1:7ed7d128d225 72 /**
Vekotin 1:7ed7d128d225 73 * Attach a callback for when a MIDIEvent is received
Vekotin 1:7ed7d128d225 74 *
Vekotin 1:7ed7d128d225 75 * @param fptr function pointer
Vekotin 1:7ed7d128d225 76 */
Vekotin 1:7ed7d128d225 77 void attach(void (*fptr)(MIDIMessage));
Vekotin 1:7ed7d128d225 78
Vekotin 1:7ed7d128d225 79
Vekotin 1:7ed7d128d225 80 protected:
Vekotin 1:7ed7d128d225 81 virtual bool EP2_OUT_callback();
Vekotin 1:7ed7d128d225 82 virtual bool USBCallback_setConfiguration(uint8_t configuration);
Vekotin 1:7ed7d128d225 83 /*
Vekotin 1:7ed7d128d225 84 * Get string product descriptor
Vekotin 1:7ed7d128d225 85 *
Vekotin 1:7ed7d128d225 86 * @returns pointer to the string product descriptor
Vekotin 1:7ed7d128d225 87 */
Vekotin 1:7ed7d128d225 88 virtual uint8_t * stringIproductDesc();
Vekotin 1:7ed7d128d225 89
Vekotin 1:7ed7d128d225 90 /*
Vekotin 1:7ed7d128d225 91 * Get string interface descriptor
Vekotin 1:7ed7d128d225 92 *
Vekotin 1:7ed7d128d225 93 * @returns pointer to the string interface descriptor
Vekotin 1:7ed7d128d225 94 */
Vekotin 1:7ed7d128d225 95 virtual uint8_t * stringIinterfaceDesc();
Vekotin 1:7ed7d128d225 96
Vekotin 1:7ed7d128d225 97 /*
Vekotin 1:7ed7d128d225 98 * Get configuration descriptor
Vekotin 1:7ed7d128d225 99 *
Vekotin 1:7ed7d128d225 100 * @returns pointer to the configuration descriptor
Vekotin 1:7ed7d128d225 101 */
Vekotin 1:7ed7d128d225 102 virtual uint8_t * configurationDesc();
Vekotin 1:7ed7d128d225 103
Vekotin 1:7ed7d128d225 104 private:
Vekotin 1:7ed7d128d225 105 void (*midi_evt)(MIDIMessage);
Vekotin 1:7ed7d128d225 106
Vekotin 1:7ed7d128d225 107 };
Vekotin 1:7ed7d128d225 108
Vekotin 1:7ed7d128d225 109 #endif