//**********************************************************************************
//code name : JOYSTICK
//name : Samin Maghsoudi_9711325
//**********************************************************************************
////////////
//old code :
////////////
// #define UPLOAD_SPEED 9600
// #define MAX 100
// #define MIN -100
// #define ANALOG_MIN 0
// #define ANALOG_MAX 1023
// #define DELAY 500
// void setup()
// {
// Serial.begin(UPLOAD_SPEED);
// }
// void loop()
// {
// uint16_t val1 = analogRead(A0);
// uint16_t val2 = analogRead(A1);
// int8_t mappedVal1 = mapNumber(val1, ANALOG_MIN, ANALOG_MAX, MIN, MAX);
// int8_t mappedVal2 = mapNumber(val2, ANALOG_MIN, ANALOG_MAX, MIN, MAX);
// Serial.print("(");
// Serial.print(mappedVal1);
// Serial.print(",");
// Serial.print(mappedVal2);
// Serial.print(")");
// Serial.println();
// delay(DELAY);
// }
// uint32_t mapNumber(uint32_t x, uint32_t sourceMin, uint32_t sourceMax, uint32_t destinationMin, uint32_t destinationMax)
// {
// return (x - sourceMin) * (destinationMax - destinationMin) / (sourceMax - sourceMin) + destinationMin;
// }
//***************************************************************************************
/////////////
//problems : not show reapetedly, not use divide
/////////////
//**********************************************************************************
//code name : JOYSTICK
//name : Samin Maghsoudi_9711325
//**********************************************************************************
////////////
//new code :
////////////
#define UPLOAD_SPEED 9600
#define MAX 100
#define MIN -100
#define ANALOG_MIN 0
#define ANALOG_MAX 1023
#define DELAY 500
#define pin1 A0
#define pin2 A1
int8_t mappedVal1Old = 0;
int8_t mappedVal2Old = 0;
void setup()
{
Serial.begin(UPLOAD_SPEED);
}
void loop()
{
uint16_t val1 = analogRead(pin1);
uint16_t val2 = analogRead(pin2);
int8_t mappedVal1New = map(val1, ANALOG_MIN, ANALOG_MAX, MIN, MAX);
int8_t mappedVal2New = map(val2, ANALOG_MIN, ANALOG_MAX, MIN, MAX);
if (mappedVal2New != mappedVal2Old || mappedVal1New != mappedVal2Old) {
Serial.print("(");
Serial.print(mappedVal1New);
Serial.print(",");
Serial.print(mappedVal2New);
Serial.print(")");
Serial.println();
delay(DELAY);
mappedVal1Old = mappedVal1New;
mappedVal2Old = mappedVal2New;
}
}