Jump to content

!Qwert

Members
  • Content Count

    10
  • Joined

  • Last visited

About !Qwert

  • Rank
    Member

Recent Profile Visitors

281 profile views
  1. Okay, I found out that using pinMode, digitalWrite and digitalRead works and I can understand how my capacitive sensor is implemented. I got my sensor to get the number of cycles I am expecting since it is allowing the sensor to be discharged and charged at a rate where I can get better readings. Since the board is running at 80MHz, one cycle is 0.0125us so if I am not touching the pin, the value will be around 40 cycles with 4M ohm pulling it high. Then if I touch the sensor, the number jumps to ~200. I am still figuring out why the port manipulation does not work but the pinMode, digitalWrite and digitalRead works. Here is how I defined my readCapacitancePin() without port manipulation: uint32_t readCapacitivePin(int pinMeasure){ //First Discharge the pin before starting pinMode(pinMeasure,OUTPUT); digitalWrite(pinMeasure,LOW); delay(1); //Charging the pin to HIGH without internal pull up //have an external resistor to pull up the pin to +5V pinMode(pinMeasure,INPUT); int cycles = 2000; //The tiva board clk is at 80MHz, tested which large value would be enough for the pin to charge and discharge the sensor //External pull-up is around 4M Ohm to +5V for(int i = 0; i < cycles; i++){ if(digitalRead(pinMeasure) == HIGH){ cycles = i; break; } } //Discharge the pin for more readings in the future pinMode(pinMeasure,OUTPUT); digitalWrite(pinMeasure,LOW); pinMode(pinMeasure,INPUT); return cycles; } Is it when pin is defined to portDATARegister(digitalPinToPort(pinToMeasure)) that it cannot tell if this is referring as an input or output so that is why every time I touch the sensor the number of cycles always the fixed value I put in readCapacitancePin()?
  2. I did some tests and concluded that my port definitions are the source of my issues. The value readCapacitivePin returns is 128. This is the case when I change the pins, the number of cycles, the resistor value and so on, meaning it will always be 128 This section of my code where I defined the port is likely the source as I checked on the oscilloscope does not give me a RC waveform: volatile uint32_t* port; //use digitalWrite volatile uint32_t* ddr; //use pinMode volatile uint32_t* pin; //use digitalRead // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; // port = (uint8_t*) &P1OUT; // ddr = (uint8_t*) &P1DIR; //bitmask = 1 << pinToMeasure; // pin = (uint8_t*) &P1IN; port = portDATARegister(digitalPinToPort(pinToMeasure)); //Input ddr = portDIRRegister(digitalPinToPort(pinToMeasure)); //Direction bitmask = 1 << pinToMeasure; pin = portDATARegister(digitalPinToPort(pinToMeasure)); //Output I looked at the documents on the pins and on energia but got nowhere as I could not get the real port,ddr and pin.
  3. Okay, after I tested this code on my tmc123g, I ran into a bad problem. When I compiled and uploaded the code, the serial monitor tells me that value of the capacitance is 128 but my main issue is that the LED lights up before I even touch my sensor. Most likely, the timing and cycles are not After looking and testing around what caused my error, I believe that the port manipulation is causing the pin to charge up be high and may not be discharging but again I cannot say for sure. I may be wrong but looking at the readCapacitivePin function I cannot make any progress on this. // Pin for the LED #define redLED RED_LED // Pin to connect to your drawing int button1N = 4; int button2N = 5; // This is how high the sensor needs to read in order // to trigger a touch. You'll find this number // by trial and error, or you could take readings at // the start of the program to dynamically calculate this. int touchedCutoff = 60; #include <Energia.h> void setup(){ Serial.begin(9600); // Set up the LED pinMode(redLED, OUTPUT); digitalWrite(redLED, LOW); } void loop(){ // If the capacitive sensor reads above a certain threshold, // turn on the LED if (readCapacitivePin(button1N) > touchedCutoff) { digitalWrite(redLED, HIGH); } else { digitalWrite(redLED, LOW); } // Every 500 ms, print the value of the capacitive sensor if ( (millis() % 500) == 0){ Serial.print("Capacitive Sensor on Pin 4 reads: "); Serial.println(readCapacitivePin(button1N)); } } // readCapacitivePin // Input: x in P1.x pin name // Output: A number, from 0 to 17 expressing // how much capacitance is on the pin // When you touch the pin, or whatever you have // attached to it, the number will get higher // In order for this to work now, // The pin should have a 1+Megaohm resistor pulling // it up to +5v. uint8_t readCapacitivePin(int pinToMeasure){ // This is how you declare a variable which // will hold the PORT, PIN, and DDR registers // on an AVR volatile uint32_t* port; //use digitalWrite volatile uint32_t* ddr; //use pinMode volatile uint32_t* pin; //use digitalRead // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; // port = (uint8_t*) &P1OUT; // ddr = (uint8_t*) &P1DIR; //bitmask = 1 << pinToMeasure; // pin = (uint8_t*) &P1IN; port = portDATARegister(digitalPinToPort(pinToMeasure)); ddr = portDIRRegister(digitalPinToPort(pinToMeasure)); bitmask = 1 << pinToMeasure; pin = portDATARegister(digitalPinToPort(pinToMeasure)); // Discharge the pin first by setting it low and output *port &= ~(bitmask); *ddr |= bitmask; delay(1); // Make the pin an input WITHOUT the internal pull-up on *ddr &= ~(bitmask); // Now see how long the pin to get pulled up int cycles = 100; for(int i = 0; i < cycles; i++){ if (*pin & bitmask){ cycles = i; break; } } // Discharge the pin again by setting it low and output // It's important to leave the pins low if you want to // be able to touch more than 1 sensor at a time - if // the sensor is left pulled high, when you touch // two sensors, your body will transfer the charge between // sensors. *port &= ~(bitmask); *ddr |= bitmask; return cycles; }
  4. Okay, Thank you for your help on this igor. I looked at the references at Energia.h for the lm4f cores and I believe for the pin register, I would use the portBASERegister for this. I do have some concerns. I found out that reason I got the error regarding the volatile uint8_t was because the example was using volatile uint8_t* port; volatile uint8_t* ddr; volatile uint8_t* pin; uint8_t values in the energia.h for MSP430. The energia.h for the ports uses uint32_t values instead so I changed them to use uint32_t: uint8_t readCapacitivePin(int pinToMeasure){ // This is how you declare a variable which // will hold the PORT, PIN, and DDR registers // on an AVR volatile uint32_t* port; //use digitalWrite volatile uint32_t* ddr; //use pinMode volatile uint32_t* pin; //use digitalRead // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; // port = (uint8_t*) &P1OUT; // ddr = (uint8_t*) &P1DIR; //bitmask = 1 << pinToMeasure; // pin = (uint8_t*) &P1IN; port = portDATARegister(digitalPinToPort(pinToMeasure)); ddr = portDIRRegister(digitalPinToPort(pinToMeasure)); bitmask = 1 << pinToMeasure; pin = portBASERegister(digitalPinToPort(pinToMeasure)); It now compiles without errors but I was wondering about that should I be concerned about the conversion from uint8_t to uint32_t, that will it may cause problems when I test it out on the TM4C123G? All I know is that it is calling unsigned integer of length of 8 bits and now I am calling unsigned integer of 32 bits (this is the first time I am using uint8_t and uint32_t). Also I think bitmask should be the same as from http://arduino.cc/en/Tutorial/BitMask, all it does is that access specific bits. If I am missing something or got something wrong, please tell me.
  5. Hi, Thanks for replying. About the other capacitive library, I am still working on it but I found this example as there is no external libraries to use and only port manipulation on the sketch to read a capacitive sensor (or voltage) reading. Also I can save up pin usage if I can complete this example. This example actually will help me understand more about how port registers and port manipulation to a degree, work between Arduino/other microcontrollers and my TM4C123G. Back to the topic, I assume that the many of the pins I have on the TM4C123G are capable of capacitive sensing. Here was an example someone did of what I am trying to attempt with only a TM4C123G: http://hackaventure.blogspot.com/2013/12/capacitive-touch-sensing-using-arm.html He only used one GPIO to read the timing of the charging and discharging of the sensor and the example I posted on this topic is very similar process. After comparing the wiring.c for each the MSP430 and TM4C123G, I think that the special functions only relate to pinMode, digitalRead and digitalWrite. I writing this as my first attempt: uint8_t readCapacitivePin(int pinToMeasure){ // This is how you declare a variable which // will hold the PORT, PIN, and DDR registers // on an AVR volatile uint8_t* port; //use digitalWrite volatile uint8_t* ddr; //use pinMode volatile uint8_t* pin; //use digitalRead // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; // port = (uint8_t*) &P1OUT; // ddr = (uint8_t*) &P1DIR; // bitmask = 1 << pinToMeasure; // pin = (uint8_t*) &P1IN; port = digitalPinToPort(pinToMeasure); bitmask = digitalPinToBitMask(pinToMeasure); When I verified this on Energia, I get these kinds of errors: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'volatile uint8_t* {aka volatile unsigned char*}' [-fpermissive] I checked that volatile uint8_t* ... is a type of array and that is how the all of the pins are called I believe and finding the ones that are used. My issue is should I have to remove the volatile uint8_t *... from the program or should I continue looking at the wiring.c for the MSP430 and TM4C123G to figure out the macros? What is it I am not getting would sum up my problems so far. It is tedious and I have looked at it for hours with not much success.
  6. I found an adaptation of a cap-sense sketch that uses port manipulation to create a capacitive sensor for Arduino to a MSP430. My question is that when I was using the sketch and adjusting it to use a tm4C123 device, I got these errors: TouchSensor.ino: In function 'uint8_t readCapacitivePin(int)': TouchSensor.ino:58:24: error: 'P1OUT' was not declared in this scope TouchSensor.ino:59:23: error: 'P1DIR' was not declared in this scope TouchSensor.ino:61:23: error: 'P1IN' was not declared in this scope I looked into this and found out on this post: http://forum.43oh.com/topic/5166-need-advice-porting-arduino-code-to-energia/ That this is using peripheral names on the MSP430 regarding registers P1DIR - to set direction P1OUT - to set an output bit P1IN - to read an input bit I remembered that wiring.c defined the port, pin and ddr. And if I commented out port = (uint8_t*) &P1OUT; ddr = (uint8_t*) &P1DIR; bitmask = 1 << pinToMeasure; pin = (uint8_t*) &P1IN; It would compile but I feel I am missing something My problem is that I was looking into how to change the peripheral names for tm4c123 instead of the MSP430 so I can use the sketch on my tm4c123. Here is the link to the sketch: https://gist.github.com/thecodemaiden/6040927
  7. Ok, correct me if I get something wrong. So the HWREG is just allowing an extension reading of the total pins available according to the memory address. For adding the rest on #define DIRECT_MODE_INPUT(base, mask) #define DIRECT_MODE_OUTPUT(base, mask) I should look further on the GPIO.c at: for DIRECT_MODE_INPUT: //***************************************************************************** void GPIOPinTypeGPIOInput(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(_GPIOBaseValid(ui32Port)); // // Make the pin(s) be inputs. // GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_IN); // // Set the pad(s) for standard push-pull operation. // GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); } //***************************************************************************** and for DIRECT_MODE_OUTPUT: //***************************************************************************** // //! Configures pin(s) for use as GPIO outputs. //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! The GPIO pins must be properly configured in order to function correctly as //! GPIO outputs. This function provides the proper configuration for those //! pin(s). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None. // //***************************************************************************** void GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(_GPIOBaseValid(ui32Port)); // // Set the pad(s) for standard push-pull operation. // GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); // // Make the pin(s) be outputs. // GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT); } I have to figure out what to write up the required base and mask values from the memory address for each one?
  8. Okay, I took the example and insert it to the header file. Of course, I saw the errors when I compiled it to see what would happen. Now I do have a new issue, you mentioned that I had to fill the Direct read and mode input/output with certain mask and base values. You also mentioned that the driverlib should give me the HWREG versions for those functions or looking at the Eneriga.h is another source to look at. Sorry that I am asking much but I am a beginner in learning how to properly port libraries. Why I need to insert something to the Direct read and mode input/output (is it the pin mapping?) and what should I look at the HWREG to type it up? Here is the link where I found the HWREG reference: https://github.com/energia/Energia/blob/master/hardware/lm4f/cores/lm4f/main.cpp
  9. Okay, I will try out the link you posted and the example code once I get the chance. Here is the cpp file along with the header file: /* CapacitiveSense.h v.04 - Capacitive Sensing Library for 'duino / Wiring https://github.com/PaulStoffregen/CapacitiveSensor http://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html http://playground.arduino.cc/Main/CapacitiveSensor Copyright (c) 2009 Paul Bagder All right reserved. Version 05 by Paul Stoffregen - Support non-AVR board: Teensy 3.x, Arduino Due Version 04 by Paul Stoffregen - Arduino 1.0 compatibility, issue 146 fix vim: set ts=4: */ #if ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #include "pins_arduino.h" #include "WConstants.h" #endif #include "CapacitiveSensor.h" // Constructor ///////////////////////////////////////////////////////////////// // Function that handles the creation and setup of instances CapacitiveSensor::CapacitiveSensor(uint8_t sendPin, uint8_t receivePin) { // initialize this instance's variables // Serial.begin(9600); // for debugging error = 1; loopTimingFactor = 310; // determined empirically - a hack CS_Timeout_Millis = (2000 * (float)loopTimingFactor * (float)F_CPU) / 16000000; CS_AutocaL_Millis = 20000; // Serial.print("timwOut = "); // Serial.println(CS_Timeout_Millis); // get pin mapping and port for send Pin - from PinMode function in core #ifdef NUM_DIGITAL_PINS if (sendPin >= NUM_DIGITAL_PINS) error = -1; if (receivePin >= NUM_DIGITAL_PINS) error = -1; #endif pinMode(sendPin, OUTPUT); // sendpin to OUTPUT pinMode(receivePin, INPUT); // receivePin to INPUT digitalWrite(sendPin, LOW); sBit = digitalPinToBitMask(sendPin); // get send pin's ports and bitmask sReg = PIN_TO_BASEREG(sendPin); // get pointer to output register rBit = digitalPinToBitMask(receivePin); // get receive pin's ports and bitmask rReg = PIN_TO_BASEREG(receivePin); // get pin mapping and port for receive Pin - from digital pin functions in Wiring.c leastTotal = 0x0FFFFFFFL; // input large value for autocalibrate begin lastCal = millis(); // set millis for start } // Public Methods ////////////////////////////////////////////////////////////// // Functions available in Wiring sketches, this library, and other libraries long CapacitiveSensor::capacitiveSensor(uint8_t samples) { total = 0; if (samples == 0) return 0; if (error < 0) return -1; // bad pin for (uint8_t i = 0; i < samples; i++) { // loop for samples parameter - simple lowpass filter if (SenseOneCycle() < 0) return -2; // variable over timeout } // only calibrate if time is greater than CS_AutocaL_Millis and total is less than 10% of baseline // this is an attempt to keep from calibrating when the sensor is seeing a "touched" signal if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) { // Serial.println(); // debugging // Serial.println("auto-calibrate"); // Serial.println(); // delay(2000); */ leastTotal = 0x0FFFFFFFL; // reset for "autocalibrate" lastCal = millis(); } /*else{ // debugging Serial.print(" total = "); Serial.print(total); Serial.print(" leastTotal = "); Serial.println(leastTotal); Serial.print("total - leastTotal = "); x = total - leastTotal ; Serial.print(x); Serial.print(" .1 * leastTotal = "); x = (int)(.1 * (float)leastTotal); Serial.println(x); } */ // routine to subtract baseline (non-sensed capacitance) from sensor return if (total < leastTotal) leastTotal = total; // set floor value to subtract from sensed value return(total - leastTotal); } long CapacitiveSensor::capacitiveSensorRaw(uint8_t samples) { total = 0; if (samples == 0) return 0; if (error < 0) return -1; // bad pin - this appears not to work for (uint8_t i = 0; i < samples; i++) { // loop for samples parameter - simple lowpass filter if (SenseOneCycle() < 0) return -2; // variable over timeout } return total; } void CapacitiveSensor::reset_CS_AutoCal(void){ leastTotal = 0x0FFFFFFFL; } void CapacitiveSensor::set_CS_AutocaL_Millis(unsigned long autoCal_millis){ CS_AutocaL_Millis = autoCal_millis; } void CapacitiveSensor::set_CS_Timeout_Millis(unsigned long timeout_millis){ CS_Timeout_Millis = (timeout_millis * (float)loopTimingFactor * (float)F_CPU) / 16000000; // floats to deal with large numbers } // Private Methods ///////////////////////////////////////////////////////////// // Functions only available to other functions in this library int CapacitiveSensor::SenseOneCycle(void) { noInterrupts(); DIRECT_WRITE_LOW(sReg, sBit); // sendPin Register low DIRECT_MODE_INPUT(rReg, rBit); // receivePin to input (pullups are off) DIRECT_MODE_OUTPUT(rReg, rBit); // receivePin to OUTPUT DIRECT_WRITE_LOW(rReg, rBit); // pin is now LOW AND OUTPUT delayMicroseconds(10); DIRECT_MODE_INPUT(rReg, rBit); // receivePin to input (pullups are off) DIRECT_WRITE_HIGH(sReg, sBit); // sendPin High interrupts(); while ( !DIRECT_READ(rReg, rBit) && (total < CS_Timeout_Millis) ) { // while receive pin is LOW AND total is positive value total++; } //Serial.print("SenseOneCycle(1): "); //Serial.println(total); if (total > CS_Timeout_Millis) { return -2; // total variable over timeout } // set receive pin HIGH briefly to charge up fully - because the while loop above will exit when pin is ~ 2.5V noInterrupts(); DIRECT_WRITE_HIGH(rReg, rBit); DIRECT_MODE_OUTPUT(rReg, rBit); // receivePin to OUTPUT - pin is now HIGH AND OUTPUT DIRECT_WRITE_HIGH(rReg, rBit); DIRECT_MODE_INPUT(rReg, rBit); // receivePin to INPUT (pullup is off) DIRECT_WRITE_LOW(sReg, sBit); // sendPin LOW interrupts(); #ifdef FIVE_VOLT_TOLERANCE_WORKAROUND DIRECT_MODE_OUTPUT(rReg, rBit); DIRECT_WRITE_LOW(rReg, rBit); delayMicroseconds(10); DIRECT_MODE_INPUT(rReg, rBit); // receivePin to INPUT (pullup is off) #else while ( DIRECT_READ(rReg, rBit) && (total < CS_Timeout_Millis) ) { // while receive pin is HIGH AND total is less than timeout total++; } #endif //Serial.print("SenseOneCycle(2): "); //Serial.println(total); if (total >= CS_Timeout_Millis) { return -2; // total variable over timeout } else { return 1; } } Thanks for your reply. I appreciate it.
  10. I have an issue when using the Capacitive Sensing Library from Arduino. I used the ver. 5 that allows non-AVR boards to use the library. My problem is when I complied it in Energia, I get these errors: /Users/apple/Documents/Energia/libraries/CapacitiveSensor/CapacitiveSensor.h:94:2: error: 'IO_REG_TYPE' does not name a type /Users/apple/Documents/Energia/libraries/CapacitiveSensor/CapacitiveSensor.h:95:11: error: 'IO_REG_TYPE' does not name a type /Users/apple/Documents/Energia/libraries/CapacitiveSensor/CapacitiveSensor.h:96:2: error: 'IO_REG_TYPE' does not name a type /Users/apple/Documents/Energia/libraries/CapacitiveSensor/CapacitiveSensor.h:97:11: error: 'IO_REG_TYPE' does not name a type I am not that strong in coding and I would like some assistance into how to solve this problem. Thanks. here is the h file where the error is coming from: #ifndef CapacitiveSensor_h #define CapacitiveSensor_h #if ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif // Direct I/O through registers and bitmask (from OneWire library) #if defined(__AVR__) #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) #define IO_REG_TYPE uint8_t #define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) #define DIRECT_MODE_INPUT(base, mask) ((*((base)+1)) &= ~(mask), (*((base)+2)) &= ~(mask)) #define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+1)) |= (mask)) #define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask)) #define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask)) #elif defined(__MK20DX128__) || defined(__MK20DX256__) #define PIN_TO_BASEREG(pin) (portOutputRegister(pin)) #define PIN_TO_BITMASK(pin) (1) #define IO_REG_TYPE uint8_t #define IO_REG_ASM #define DIRECT_READ(base, mask) (*((base)+512)) #define DIRECT_MODE_INPUT(base, mask) (*((base)+640) = 0) #define DIRECT_MODE_OUTPUT(base, mask) (*((base)+640) = 1) #define DIRECT_WRITE_LOW(base, mask) (*((base)+256) = 1) #define DIRECT_WRITE_HIGH(base, mask) (*((base)+128) = 1) #elif defined(__SAM3X8E__) #define PIN_TO_BASEREG(pin) (&(digitalPinToPort(pin)->PIO_PER)) #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) #define IO_REG_TYPE uint32_t #define IO_REG_ASM #define DIRECT_READ(base, mask) (((*((base)+15)) & (mask)) ? 1 : 0) #define DIRECT_MODE_INPUT(base, mask) ((*((base)+5)) = (mask)) #define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+4)) = (mask)) #define DIRECT_WRITE_LOW(base, mask) ((*((base)+13)) = (mask)) #define DIRECT_WRITE_HIGH(base, mask) ((*((base)+12)) = (mask)) #elif defined(__PIC32MX__) #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) #define IO_REG_TYPE uint32_t #define IO_REG_ASM #define DIRECT_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0) //PORTX + 0x10 #define DIRECT_MODE_INPUT(base, mask) ((*(base+2)) = (mask)) //TRISXSET + 0x08 #define DIRECT_MODE_OUTPUT(base, mask) ((*(base+1)) = (mask)) //TRISXCLR + 0x04 #define DIRECT_WRITE_LOW(base, mask) ((*(base+8+1)) = (mask)) //LATXCLR + 0x24 #define DIRECT_WRITE_HIGH(base, mask) ((*(base+8+2)) = (mask)) //LATXSET + 0x28 #endif // some 3.3V chips with 5V tolerant pins need this workaround // #if defined(__MK20DX256__) #define FIVE_VOLT_TOLERANCE_WORKAROUND #endif // library interface description class CapacitiveSensor { // user-accessible "public" interface public: // methods CapacitiveSensor(uint8_t sendPin, uint8_t receivePin); long capacitiveSensorRaw(uint8_t samples); long capacitiveSensor(uint8_t samples); void set_CS_Timeout_Millis(unsigned long timeout_millis); void reset_CS_AutoCal(); void set_CS_AutocaL_Millis(unsigned long autoCal_millis); // library-accessible "private" interface private: // variables int error; unsigned long leastTotal; unsigned int loopTimingFactor; unsigned long CS_Timeout_Millis; unsigned long CS_AutocaL_Millis; unsigned long lastCal; unsigned long total; IO_REG_TYPE sBit; // send pin's ports and bitmask volatile IO_REG_TYPE *sReg; IO_REG_TYPE rBit; // receive pin's ports and bitmask volatile IO_REG_TYPE *rReg; // methods int SenseOneCycle(void); }; #endif
×
×
  • Create New...