#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
//Adafruit_ADS1015 ads; /* Use this for the 12-bit version */
int16_t adcValues[4];
const unsigned long intervalMicros = 1; // 1162 Az ADS1115 modul mintavételezési sebességének megfelelő érték
unsigned long previousMicros = 0;
void setup(void)
{
Serial.begin(9600);
Serial.println("Hello!");
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1);
}
}
void loop(void) {
unsigned long start = micros();
unsigned long currentMicros = micros();
if (currentMicros - previousMicros >= intervalMicros) {
// ADC értékek olvasása az összes csatornáról egyszerre
for (int i = 0; i < 4; i++) {
adcValues[i] = ads.readADC_SingleEnded(i);
}
// Gamepad report frissítése
//Gamepad.xAxis(adcValues[0]); // X tengely
//Gamepad.yAxis(adcValues[1]); // Y tengely
//Gamepad.zAxis(adcValues[2]); // Z tengely
//Gamepad.write();
Serial.println("-----------------------------------------------------------");
Serial.print("AIN0: "); Serial.print(adcValues[0]); Serial.print(" ");
Serial.print("AIN1: "); Serial.print(adcValues[1]); Serial.print(" ");
Serial.print("AIN2: "); Serial.print(adcValues[2]); Serial.print(" ");
Serial.print("AIN3: "); Serial.print(adcValues[3]); Serial.print(" ");
unsigned long end = micros();
unsigned long delta = end - start;
Serial.print("szum loop delay: ");
Serial.print(delta);
Serial.print(" ");
previousMicros = currentMicros;
}
}