I haven't received my pas sensor yet (Peddle Assist Sensor) and so have left the pin not connected, however for some reason, when I operate the trigger on AnalogPin 3 the value increases for AnalogPin 2
Here is my code:
/*********************************************************************
This is a direct hack of adafruits ssd1306*64 i2c file
Todo
Add PAS (Pedal Assist Sensor) control code
Actual Motor output to Motpin
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/* HAll503 Config */
int ThrotPin = 3; // Throttle Hall Sensor
int Th = '0'; // Variable th stores reading from HALL503
/* End of HAll503 Config */
int Motpin = 9; // PWM output pin for brused motor control.
/* Motor Control */
int PasPin = 2; // PAS Pin
int Pas = '0';
/* PAS Sensor */
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000011, B11000000,
B00001100, B00110000,
B00010000, B00001000,
B00100000, B00000100,
B01000100, B00000010,
B01000100, B00000010,
B10000100, B00000001,
B10000010, B00000001,
B10000010, B00000001,
B10000010, B00000001,
B01000000, B00000010,
B01000001, B10000010,
B00100011, B11000100,
B00010000, B00001000,
B00001100, B00110000,
B00000011, B11000000, };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
Serial.begin(9600); // Only for debugging.
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
}
void loop()
{
display.clearDisplay();
display.drawBitmap(1, 1, logo16_glcd_bmp, 16, 16, 1);
// text display tests
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20,0);
Th = analogRead(ThrotPin); // read the input pin
Serial.println(Th); //Prints to Serial terminal
display.println(Th); //Prints to display
display.setCursor(0,20);
Pas = analogRead(PasPin);
display.println(Pas);
display.display();
delay(10);
// analogWrite(Motpin, Th / 4); // Analogue read is 0-1024, Analogue write is 0-256
}
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
}
void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
for (uint8_t i=0; i < 168; i++) {
if (i == '\n') continue;
display.write(i);
if ((i > 0) && (i % 21 == 0))
display.println();
}
display.display();
}
Is this a coding error or a hardware issue?