Can't find problem with my code

Hi, I'm brand new to using an Arduino and do not know anything about using it. I have been trying to use a micro switch to when pressed type the letter L. I have just been using codes from other projects and splicing them together. This is what I have now, it is not working and any help would be greatly appreciated.

#include <ezButton.h>
#include <Keyboard.h>

ezButton limitSwitch(7);  // create ezButton object that attach to pin 7;

int pinL = 7;

void setup() {
  Serial.begin(9600);
  limitSwitch.setDebounceTime(50); // set debounce time to 50 milliseconds
{

pinMode(pinL, INPUT_PULLUP);

}

void loop(); {
 limitSwitch.loop(); // MUST call the loop() function first

  if(limitSwitch.isPressed())
    Serial.println("The limit switch: UNTOUCHED -> TOUCHED");

  if(limitSwitch.isReleased())
    Serial.println("The limit switch: TOUCHED -> UNTOUCHED");

  int state = limitSwitch.getState();
  if(state == HIGH)
    Serial.println("The limit switch: UNTOUCHED");
  else
    Serial.println("The limit switch: TOUCHED");

if (digitalRead(pinL) == LOW)  
  {
    Keyboard.write('L');
    delay(500);
  }
}

It tells me "Keyboard not found", if anyone could help it would be great. I know it sounds like a simple project but I just started today.

You may need to install the keyboard.h library.

Use the library manager in the IDE and your best common sense and google.

Also… what Arduino board are you using? Rhey do not all work with that code.

a7

I'm sure it tells you not exactly that. You should post the (full) error message literally. But I think that it's enough in this case.

Keyboard.h and mouse.h only work for boards with native USB. Which board are you using?

Thanks for using code tags in your first post.

void loop(); {

Lose the

;


void setup() {
  Serial.begin(9600);
  limitSwitch.setDebounceTime(50); // set debounce time to 50 milliseconds
{
pinMode(pinL, INPUT_PULLUP);

}

Every { needs a friend }


Coping and pasting code then asking why your attempt doesn’t work is quite a way of learning ! :weary:

I just realized that my board is not capatable, I'm using a Nano. Is there any way I could still do what I'm trying to do, or will I have to upgrade my board?

Whenever I delete the semicolon it gives me a different error. "a function-definition is not allowed here before '{' token"

You need to fix setup( ) too.

Sorry, could you clarify what I need to fix on setup.

You need to read the posts that people are giving you.


Ie lose the } above your pinMode in setup. ….

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.