martin2250 / ADCTouch

touch sensing library for Arduino
MIT License
100 stars 24 forks source link

Attiny 0/1 series #11

Open agrimagsrl opened 2 years ago

agrimagsrl commented 2 years ago

Is there any chance you can support the new Attiny 0/1 series? ADMUX is not defined (in the Arduino IDE at least).

martin2250 commented 2 years ago

Hi Simone, I currently don't have time to work on adding support for new chips. That said, if you (or someone else) want to work on it, I'd be happy to accept pull requests 😉 Cheers

agrimagsrl commented 2 years ago

I wish I could understand half the code you wrote... I know nothing about registers. I found a different approach that works for my use-case. I will report here just in case someone else needs it. It's dirty naive, but I only need to get a rough idea of how much a touch sensor was "touched".

uint16_t read(uint8_t pin) {
        // write HIGH to pin, then LOW, then read its voltage
        pinMode(pin, OUTPUT);
        digitalWrite(pin, HIGH);
        delay(50);
        digitalWrite(pin, LOW);
        pinMode(pin, INPUT);

        uint16_t readings[numReadings];
        uint16_t sum = 0;

        for (int i = 0; i < numReadings; i++)
          readings[i] = analogRead(pin);

        for (int i = 0; i < numReadings; i++)
          sum += readings[i];

        return sum / numReadings;
    }
hghile commented 4 months ago

Seems like this should do it?
https://github.com/SpenceKonde/ADCTouch/tree/master/src