Author Topic: Digispark Send multiple arrow key commands  (Read 1926 times)

K.M65

  • Newbie
  • *
  • Posts: 3
Digispark Send multiple arrow key commands
« on: February 17, 2019, 01:34:58 am »
Hi there

Does anybody know how to send multiple inputs of the arrow keys?  For example if i needed to press the down arrow key 10 times, how would this be coded for the digispark.

Many thanks

granzeier

  • Jr. Member
  • **
  • Posts: 73
Re: Digispark Send multiple arrow key commands
« Reply #1 on: February 18, 2019, 03:13:20 am »
This should do what you want:

This is from a project I did last year; I run the slides for our church, and wanted to cycle through some announcements before service began.

Code: [Select]
/*
  Announcements

  Sends a home key press, followed by 7 right arrow key presses to the computer,
  and flashes an LED connected to digital pin 1 each time.
  This allows an announcement period for LibreOffice Impress slide shows

  Start your slide show in LibreOffice Impress, or PowerPoint
  and then insert the DigiSpark to create the announcements slide show
  When you are ready for your service, or presentation, just pull the DigiSpark.

  The circuit (Digispark):
  - Built-in LED attached from pin 1 to ground - Change this if you are using the other version of the DigiSpark

  created 2018-06-16
  by Art G. Granzeier III <http://www.granzeier.com>

  This example code is in the public domain.

*/

#include <DigiKeyboard.h>

// constants won't change. They're used here to set pin numbers:
const int ledPin =  1;       // the number of the LED pin

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // this is generally not necessary but with some older systems it seems to
  // prevent missing the first character after a delay:
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.sendKeyStroke(74); // Send HOME key stroke to start slide show at the beginning
  // DigiKeyboard.sendKeyStroke(0);
}

void loop() {

  for (int i=0; i < 7; i++) { // This limit to i will be the number of slides that you want repeated for announcements
    DigiKeyboard.sendKeyStroke(79); // Send the right arrow key stroke to advance to the next slide
    digitalWrite(ledPin, 1);
    DigiKeyboard.delay(500);
    digitalWrite(ledPin,0);
    // DigiKeyboard.sendKeyStroke(0);
    DigiKeyboard.delay(5000);  // Pause for 5 seconds so audience may read announcement
  }
 
  DigiKeyboard.sendKeyStroke(74); // Send HOME key stroke to start slide show over
  digitalWrite(ledPin, 1);
  DigiKeyboard.delay(500);
  digitalWrite(ledPin,0);
  // DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(5000);  // Pause for 5 seconds so audience may read first announcement
}

The keycodes were kind of difficult - I used a chart similar to the ones here: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.keyboardtechref/doc/kybdtech/Key.htm
« Last Edit: February 18, 2019, 03:30:04 am by granzeier »

K.M65

  • Newbie
  • *
  • Posts: 3
Re: Digispark Send multiple arrow key commands
« Reply #2 on: February 18, 2019, 04:15:47 am »
excellent, thank you that seems to be what i am looking for.

Many thanks

granzeier

  • Jr. Member
  • **
  • Posts: 73
Re: Digispark Send multiple arrow key commands
« Reply #3 on: February 18, 2019, 02:01:22 pm »
Glad I could help.
When you get it working, post it on the Projects board (http://digistump.com/board/index.php/board,2.0.html).