First of all i just want to say that if this is in the wrong directory on the forum i apologize!!
Ok i just want to also say that i am a TOTAL noob at this Arduino programming/coding thing and i have absolutely no clue what im doing!!.
I have purchased a kit to build an 18 speed shifter for American Truck Simulator. The kit comes with everything i need except a programmed Arduino Micro Pro. the kit consists of two Hall effect Sensors that will act as a Range splitter and one for a gear splitter. i looked around on google and i have the Arduino IDE installed on my PC and have attempted to used this code:
When i attempt to upload said code onto the Arduino board it returns an error regarding the "void setup" area of the code. If anyone could help me with this i would greatly appreciate it, if there is a code out there that anyone knows of that works that would also be greatly appreciated!!
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Please post the entire code, here. Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Did you choose the right board (Arduino AVR Boards, Ardjuino Micro) in the Tools, Boards menu?
// File: Truck_Simulator_V1.0.ino
// Author: Ingmar Kroon
// Instructions are found at https://github.com/ingmar12345/rangesplitter_arduino_leonardo
#include "Keyboard.h"
const int rangePin = 4; // or whatever pin you like
const int splitterPin = 5;
// const int easyjakePin = 6; // my knob does not have an easy jake button, uncomment if you do have one
int rangeFlag = LOW;
int splitterFlag = LOW;
int rangeState = LOW;
int splitterState = LOW;
// int easyjakeFlag = LOW;
// int easyjakeState = LOW;
void setup() {
pinMode(rangePin, INPUT_PULLUP);
pinMode(splitterPin, INPUT_PULLUP);
if (digitalRead(rangePin) == LOW) rangeFlag = LOW;
else rangeFlag = LOW;
if (digitalRead(splitterPin) == LOW) splitterFlag = LOW;
else splitterFlag = LOW;
/*
if(digitalRead(easyjakePin) == LOW) easyjakeFlag = LOW;
else easyjakeFlag = LOW;
*/
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// read the buttons:
rangeState = digitalRead(rangePin);
splitterState = digitalRead(splitterPin);
// splitter switch
if ((splitterState == HIGH) && (splitterFlag == LOW))
{
//Keyboard.println("Splitter switch is HIGH"); // do not uncomment while playing ETS2 and ATS, only for testing purposes
Keyboard.print("Z");
splitterFlag = HIGH;
delay(100);
}
if ((splitterState == LOW) && (splitterFlag == HIGH))
{
//Keyboard.println("Splitter switch is LOW");
Keyboard.print("Z");
splitterFlag = LOW;
delay(100);
}
// range switch
if ((rangeState == HIGH) && (rangeFlag == LOW))
{
//Keyboard.println("Range switch is HIGH");
Keyboard.print("X");
rangeFlag = HIGH;
delay(100);
}
if ((rangeState == LOW) && (rangeFlag == HIGH))
{
//Keyboard.println("Range switch is LOW");
Keyboard.print("X");
rangeFlag = LOW;
delay(100);
}
// easyjake switch
/*
if((easyjakeState == HIGH) && (easyjakeFlag == LOW))
{
//Keyboard.println("easyjake switch is HIGH");
Keyboard.print("V");
easyjakeFlag = HIGH;
delay(100);
}
if((easyjakeState == LOW) && (easyjakeFlag == HIGH))
{
//Keyboard.println("easyjake switch is LOW");
Keyboard.print("V");
easyjakeFlag = LOW;
delay(100);
}
*/
}
i opened the IDE software to recompile the code to paste the error and when i compiled it it compiled without error tonight. i attempted to upload code to board and it said missing keyboard.h library and gave a file path to place it which i did and it uploaded without error. i had the port set to Arduino Leonardo and the com port selected properly. tonight it just simply worked for some reason.
@Riva i did have the board correctly selected but as i just mentioned it compiled and uploaded to the board without error.
I still have an issue though. i have the Hall Effect sensors soldered up and i am attempting to test them to see if the sensors are working as they should. i know on controllers i can go into Devices and printers and select the controllers (using xbox for windows controller as example here) i can go into the controller settings and see the little red dots with the button numbers as well as all the various axis of movements the controller has. i see the "Arduino Leonardo" under the devices section but when i right click on it i see nothing that says "game controller options" this is where i can see the red dots and what buttons are what numbers etc.
does the "keyboard.h" file set the Arduino up as a keyboard input? if this is what that file does how do i change it to be a "joysitck" plug and play controller?
@johnwasser i havent gotten that far as i want to make sure it works before i have it all together and then have to take it apart to fix it if it doesnt work.