#define RD_LD_PIN 18
#define GRN_LD_PIN 19
#define BL_LD_PIN 22
#define RD_TOUCH_BTN 4
#define GRN_TOUCH_BTN 2
#define BL_TOUCH_BTN 15
int RD_TOUCH_DATA = 0;
int GRN_TOUCH_DATA = 0;
int BL_TOUCH_DATA = 0;
int RD_TOUCH_MAP = 0;
int GRN_TOUCH_MAP = 0;
int BL_TOUCH_MAP = 0;
int RD_TOUCH_ST = LOW;
int GRN_TOUCH_ST = LOW;
int BL_TOUCH_ST = LOW;
#define potPin 13
#define PWMChannel 0
//const int freq = 5000;
//const int resolution = 12;
//const int resolution = 8;
//uint16_t dutyCycle;
int HALL_DATA = 0;
int potData = 0;
float voltage = 0.0;
void setup() {
// put your setup code here, to run once:
pinMode(RD_LD_PIN, OUTPUT);
pinMode(GRN_LD_PIN, OUTPUT);
pinMode(BL_LD_PIN, OUTPUT);
pinMode(RD_TOUCH_BTN, INPUT);
pinMode(GRN_TOUCH_BTN, INPUT);
pinMode(BL_TOUCH_BTN, INPUT);
//ledcSetup(PWMChannel, freq, resolution);
//ledcAttachPin(RD_LD_PIN, PWMChannel);
//ledcAttachPin(GRN_LD_PIN, PWMChannel);
//ledcAttachPin(BL_LD_PIN, PWMChannel);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
HALL_DATA = hallRead();
Serial.print("\n\nHall Effect =");
Serial.println(HALL_DATA);
RD_TOUCH_DATA = analogRead(RD_TOUCH_BTN);
RD_TOUCH_MAP = map(RD_TOUCH_DATA, 0, 4095, 0, 60);
Serial.print("TouchRD = ");
Serial.print(RD_TOUCH_MAP);
GRN_TOUCH_DATA = analogRead(GRN_TOUCH_BTN);
GRN_TOUCH_MAP = map(GRN_TOUCH_DATA, 0, 4095, 0, 60);
Serial.print(" TouchGRN = ");
Serial.print(GRN_TOUCH_MAP);
BL_TOUCH_DATA = analogRead(BL_TOUCH_BTN);
BL_TOUCH_MAP = map(BL_TOUCH_DATA, 0, 4095, 0, 60);
Serial.print(" TouchBL = ");
Serial.print(BL_TOUCH_MAP);
potData = analogRead(potPin);
Serial.print("\tPotentiometer = ");
Serial.println(potData);
voltage = (float)potData / 4095 * 3.3;
Serial.print("\tVoltage = ");
Serial.println(voltage);
//dutyCycle = map(potData, 0, 4095, 0, 255);;
//ledcWrite(PWMChannel, potData);
//ledcWrite(PWMChannel, dutyCycle);
if (HALL_DATA > 40 || HALL_DATA < 60){
digitalWrite(RD_LD_PIN, HIGH);
digitalWrite(GRN_LD_PIN, HIGH);
digitalWrite(BL_LD_PIN, HIGH);
}
else{
digitalWrite(RD_LD_PIN, LOW);
digitalWrite(GRN_LD_PIN, LOW);
digitalWrite(BL_LD_PIN, LOW);
}
digitalWrite(RD_LD_PIN, LOW);
digitalWrite(GRN_LD_PIN, LOW);
digitalWrite(BL_LD_PIN, LOW);
if (RD_TOUCH_MAP > 50 || RD_TOUCH_MAP != 0) {
digitalWrite(RD_LD_PIN, HIGH);
delay(100);
}
else {
digitalWrite(RD_LD_PIN, LOW);
delay(100);
}
if (GRN_TOUCH_MAP > 50 || GRN_TOUCH_MAP != 0) {
digitalWrite(GRN_LD_PIN, HIGH);
delay(100);
}
else {
digitalWrite(GRN_LD_PIN, LOW);
delay(100);
}
if (BL_TOUCH_MAP > 50 || BL_TOUCH_MAP != 0) {
digitalWrite(BL_LD_PIN, HIGH);
delay(100);
}
else {
digitalWrite(BL_LD_PIN, LOW);
delay(100);
}
}