Could you help me with this code?

<* * Generated with <3 by Dckuino.js, an open source project ! */

#include <avr/pgmspace.h>
#include "DigiKeyboard.h"

const char line1[] PROGMEM = "notepad.exe";
const char line2[] PROGMEM = "Hello World!";

char buffer[256];

#define GetPsz(x) (strncpy_P(buffer, (char*)x, 256))
#define KEY_UP_ARROW 0x52
#define KEY_DOWN_ARROW 0x51
#define KEY_LEFT_ARROW 0x50
#define KEY_RIGHT_ARROW 0x4F
#define KEY_LEFT_GUI 0xE3
#define KEY_ESC 0x29
#define KEY_TAB 0x2B

void digiBegin() {
DigiKeyboard.sendKeyStroke(0,0);
DigiKeyboard.delay(50);
}

void digiEnd() {
const int led=1;
pinMode(led, OUTPUT);
while (1) {
digitalWrite(led, !digitalRead(led));
DigiKeyboard.delay(1000);
}
}

void printText(char *txt) {
DigiKeyboard.print(txt);
DigiKeyboard.update();
}

void setup() {
digiBegin();

DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);

DigiKeyboard.delay(50);

// notepad.exe printText(GetPsz(line1));

DigiKeyboard.sendKeyStroke(KEY_ENTER);

DigiKeyboard.delay(100);

// Hola Mundo! printText(GetPsz(line2));

digiEnd();
} /* No utilizados bucle infinito */ void loop() {}
/>

Okey this code compile without problems but when I tried in my digispark it couldn´t print any stroke. Could you help me ,please?

Hi, @mary4434
Welcome to the forum.

Thanks.. Tom... :smiley: :+1: :australia: :coffee:

Thanks Tom could you help me?

Can you help us by using code tags (the </> icon above the compose window) to make it easier to read and copy for examination?

Edit post#1 to insert code tags, please.

I have a few of those from never mind how long ago. They are cute, but seemed like a PITA to work with, kinda fussy.

Have you been able to run simple programs like the blink sketch, doing nothing but blinking an LED?

And then a baby step further? Check a pushbutton, that kind of thing?

a7

What exactly are you expecting the code to do, and what is it doing differently?

You have commented out the lines that print the text, looks like all you will get is come cursor movement and an ENTER key.

Using a 256 element array for printing text from PROGMEM is very inefficient use of memory, either pull a character at a time from PROGMEM until the end of the string, or if the library inherits from print direct use of a pointer to PROGMEM will work if you cast to __FlashStringHelper*

I think these two lines were intended to be two lines each:

  // notepad.exe 
  printText(GetPsz(line1));

  // Hola Mundo! 
  printText(GetPsz(line2));

I am expecting that they do print when you press a random keystroke.

could you give me a example of code with this array please?

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