Go Down

Topic: Translate Teensy Code into Arduino Uno R3 or Leonardo (Read 8769 times) previous topic - next topic

Sep 10, 2013, 08:11 pm Last Edit: Sep 10, 2013, 09:42 pm by khalilalucard Reason: 1
Hi everybody,

I try to tranlate this code into my arduino. This code should generate a serial of number to 0000 to 9999. I try to made a code but it dosnt work. It generate letters and other characters but not numbers. If someone can correct i will be very happy.

Sorry for my english if i made some mistake. It's not my mother tongue.

Thank you

The original code :

Code: [Select]
#include <usb_keyboard.h>
const int ledPin = 13; // choose the pin for the LED
int counter = 0;
int fakecounter = counter;
char pin[]="xxxx";
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
delay(10000);
}
void loop(){
keyboard_modifier_keys = 0;
if (counter <= 9999){
delay(8000);
digitalWrite(ledPin, LOW);
delay(5500);
digitalWrite(ledPin, HIGH);
sprintf(pin, "%04d", fakecounter);
//sending first digit
Keyboard.press(pin[0]);
delay(450);
Keyboard.release(pin[0]);
delay(420);
//sending second digit
Keyboard.press(pin[1]);
delay(398);
Keyboard.release(pin[1]);
delay(510);
//sending third digit
Keyboard.press(pin[2]);
delay(421);
Keyboard.release(pin[2]);
delay(423);
//sending forth digit
Keyboard.press(pin[3]);
delay(430);
Keyboard.release(pin[3]);
delay(525);
//sending enter
Keyboard.press(KEY_ENTER);
delay(305);
Keyboard.release(KEY_ENTER);
}
//reached 4 digit PIN max value
if (counter > 9999){
for (int blinkies = 0; blinkies < 8; blinkies++) {
digitalWrite(ledPin, HIGH);
delay(20);
digitalWrite(ledPin, LOW);
delay(200);
}
delay(6000);
}
++counter;
fakecounter = counter;
}


The sketch i made :


Code: [Select]
const int ledPin = 13;
int counter = 0;

int loops = 0;
int value0 = 0;
int value1 = 0;
int value2 = 0;
int value4 = 0;
int fakecounter = counter;
char pin[]="xxxx";
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
delay(200);
}
void loop(){
if (counter <= 9999){
delay(8000);
digitalWrite(ledPin, LOW);
delay(5500);
digitalWrite(ledPin, HIGH);
sprintf(pin, "%04d", fakecounter);
//First Digit
int value0 = pin[0] - '0';
buf[3] = value0 + 29;
if (buf[3] = 30){
buf[3] = value0 + 29;
Serial.write(buf, 8);
delay(450);
releaseKey();
delay(420);
}
//Second Digit
int value1 = pin[1] - '0';
buf[3] = value1 + 29;
if (buf[3] = 30){
buf[3] = value1 + 29;
Serial.write(buf, 8);
delay(398);
releaseKey();
delay(510);
}
//Third Digit
int value2 = pin[2] - '0';
buf[3] = value2 + 29;
if (buf[3] = 30){
buf[3] = value2 + 29;
Serial.write(buf, 8);
delay(421);
releaseKey();
delay(423);
}
//Forth Digit
int value3 = pin[3] - '0';
buf[3] = value3 + 29;
if (buf[3] = 30){
buf[3] = value3 + 29;
Serial.write(buf, 8);
delay(430);
releaseKey();
delay(525);
}
//Enter Key
buf[3] = 40;
Serial.write(buf, 8);
delay(305);
releaseKey();
}
//reached 4 digit PIN max value
if (counter > 9999){
for (int blinkies = 0; blinkies < 8; blinkies++) {
digitalWrite(ledPin, HIGH);
delay(20);
digitalWrite(ledPin, LOW);
delay(200);
}
delay(6000);
}
++counter;
fakecounter = counter;
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
buf[3] = 0;
Serial.write(buf, 8); // Release key
}

Grumpy_Mike

Look at that code you posted, all those cool similes, are they in the code? ... No.

This is why we ask users to use code tags, this is explained in the how to use this forum sticky post.
Read it and modify that original post please.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#3
Sep 10, 2013, 09:38 pm Last Edit: Sep 10, 2013, 09:43 pm by khalilalucard Reason: 1
Oh sorry. I didn't see. I will correct this.

Thank you

Jantje

Which teensy do you use to have a led on pin 13?
The uno does not support keyboard emulation and your "original sketch" does keyboard emulation so that should not translate to UNO at all.
The leonardo does have keyboard emulation (as it is the exact same chip as teensy 2) but you are not using a keyboard library in your new sketch.
In other word: it is completely unclear to me what you are trying to do and why you have translation problems.
Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

AWOL

Code: [Select]
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
buf[3] = 0;
Serial.write(buf, 8); // Release key
}

What about but [1] ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Hi janjte,

The model of the teesny is the 2.0+ or 3.0. I know that the UNO can't be used as HID. I follow this website to turn my uno r3 into HID http://mitchtech.net/arduino-usb-hid-keyboard/ but when i try it on notepad, it send only wwww and not number.
So this morning i shop a Leonardo card but i didn't watch it now.
Can you tell me where should be the problem ?

Thank you

Hi AWOL,

I make the correction and i will try this. I'll tell you if it works.

Thank you

Jantje

what is wrong?
First of all it looks like you are trying to write a hacking program entering pin codes on one or another program.
secondly

Code: [Select]
if (buf[3] = 30)
Always true.
Oh dear.



Due to 1 I will not comment any more unless you give a really good explanation what this project of yours is about.

jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Hi janjte,
As you say it's a bruteforce: http://orvtech.com/en/howto/atacar-efi-pin-macbook-pro/
My Macbook air crashed last week and when i try to clear it, it ask me a code. I called Apple and they told me that my  warranty is over (i bought my mac in 2011). So they ask me 150 euros for send a key but i said them that i never did this code. So i am stuck. I buy an other macbook pro friday because i need a computer for school and my macbook air is too old :p

So that's all. I buy the starter kit for arduino last week because i will start my project for school, an engeener project in  embedded system. It talk about drones, and when i see the website of ovrtech, i though i could try to use his sketch into my R3. But if it doesn't work it's not a big deal, i'll just clear my session and create an other and sell my macbook like that.

Hi jantjte,

Can you explain me why this part of code is always true ?

Code: [Select]
if (buf[3] = 30)


Thank you

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty


Hi jantjte,

Can you explain me why this part of code is always true ?

Code: [Select]
if (buf[3] = 30)


Thank you


Because
Code: [Select]
if (buf[3] = 30)

works different then:
Code: [Select]
if (buf[3] == 30)

Lefty


Hi everybody,

Oh god it's clear that '=' is totaly different that '=='.
I will try this. I'll told you if it's works.



Thank you everybody.

Hi,

Finally it doesn't work. I think this will not work, because when i test it, I always have a random characters and not a counter of number (0, 1, 2 , ..., 9). Maybe the ATMEGA328P in the Arduino Uno  is not working with this flash. I will try to do an other sketch with the Arduino Leonardo. I see into the arduino software a model of "keyboardandmouse" sketch so i will start with this. I'll post it when i'am finish.

Hope this will work :p

Thank you buddies

Go Up