I am new to Arduino but have been programming for a number of years.
This script is meant to control an analogue input from my Hall Sensor and map it to an analogue Joystick axis. The Joystick.h library is working and I have tested it with other scripts however when I try to compile this new code I get an "expected unqualified-id before '{' token" error:
larryd:
Use CTRL T in the IDE to format your code.
Before you do that, Use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Use blank lines sparingly, no more than one at a time.
aarg:
Before you do that, Use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Use blank lines sparingly, no more than one at a time.
Thanks for the help so far. I have been working on this and had to scrap the previous code as I couldn't get it working properly.
I now have some updated code :
const int ledPin = 13;//the led attach to pin13
int sensorPin = A2; // select the input pin for the potentiometer
int digitalPin = 7; //D0 attach to pin7
int sensorValue = 0;// variable to store the value coming from A2
boolean digitalValue = 0; // variable to store the value coming from pin7
#include "Joystick.h"
Joystick_ Joystick;
void testThrottleRudder(unsigned int value)
{
Joystick.setThrottle(value);
Joystick.setRudder(value);
}
void setup()
{
Joystick.begin();
pinMode(digitalPin, INPUT); //set the state of D0 as INPUT
pinMode(sensorPin, INPUT_PULLUP); //set the state of D0 as INPUT
pinMode(ledPin, OUTPUT); //set the state of pin13 as OUTPUT
Serial.begin(9600); // initialize serial communications at 9600 bps
Joystick.setThrottleRange(0, 255);
}
void loop()
{
sensorValue = analogRead(sensorPin); //read the value of A2
digitalValue = digitalRead(digitalPin); //read the value of D0
Serial.print("Sensor Value "); // print label to serial monitor
Serial.println(sensorValue); //print the value of A2
Serial.print("Digital Value "); // print label to serial monitor
Serial.println(digitalValue); //print the value of D0 in the serial
if ( digitalValue == HIGH ) //if the value of D0 is HIGH
{
digitalWrite(ledPin, LOW); //turn off the led
}
if ( digitalValue == LOW) //else
{
digitalWrite(ledPin, HIGH); //turn on the led
}
delay(200);//delay 200ms
}
The problem I have now is that I can not take the values from the Hall Sensor and map them to the Throttle axis.
This feels like progress, at least now the serial viewer now picks up the Hall sensor inputs and also installs the Joystick drivers. All that's left is to MAP the Hall Sensor inputs to an axis.
Any help would really be appreciated about now as I am struggling to see whats missing