Rubber Ducky for arduino due

This commit is contained in:
plane000
2018-08-15 15:50:59 +01:00
parent c18d9afaa5
commit caff458774
2 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
#include <Mouse.h>
#include <Keyboard.h>
void setup() {
Keyboard.begin();
Mouse.begin();
delay(1000);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
Keyboard.releaseAll();
delay(100);
Keyboard.print("cmd");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(100);
Keyboard.print("tree");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
}
void loop() {}

View File

@@ -0,0 +1,49 @@
uint32_t pwmPin = 8;
uint32_t maxDutyCount = 2;
uint32_t clkAFreq = 34000000ul;
uint32_t pwmFreq = 34000000ul;
uint32_t channel;
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, 0);
pmc_enable_periph_clk(PWM_INTERFACE_ID);
PWMC_ConfigureClocks(clkAFreq, 0, VARIANT_MCK);
PIO_Configure(
g_APinDescription[pwmPin].pPort,
g_APinDescription[pwmPin].ulPinType,
g_APinDescription[pwmPin].ulPin,
g_APinDescription[pwmPin].ulPinConfiguration);
channel = g_APinDescription[pwmPin].ulPWMChannel;
PWMC_ConfigureChannel(PWM_INTERFACE, channel , pwmFreq, 0, 0);
PWMC_SetPeriod(PWM_INTERFACE, channel, maxDutyCount);
PWMC_EnableChannel(PWM_INTERFACE, channel);
PWMC_SetDutyCycle(PWM_INTERFACE, channel, 1);
digitalWrite(13, 1);
}
void loop() {
note(200, 300); // 300Hz for 3000ms
delay(200);
}
void note(int duration, int f) {
int del = (1000000 / f) / 2;
int c = (duration * 1000) / del;
bool x = true;
for (long i = 0; i < c; i++) {
if (x) {
PWMC_SetDutyCycle(PWM_INTERFACE, channel, 1);
}
else {
PWMC_SetDutyCycle(PWM_INTERFACE, channel, 0);
}
delayMicroseconds(del);
x = !x;
}
}