Jump to content

[Version 1] Beating Heart


Recommended Posts

I was trying to get a feel for system delays and general programming flow when using teensy. So I thought I would just do this for the heck of it, and when I did it..... why not share it . It will make someone happy for sure. Understand the risks if you are planning to run it. Do not run on slow systems.

Few things learnt while doing this.

  • Delays are so damm important and they are just varying from system to system. Almost need to think of slowest machines.That brings to my second point.
  • Feed back from the system is critical, we need to figure out how to get some feedback from system.

/*
.prints the obfuscated ascii heart
.gets the heart into recognizable shape
.says I love you
.beats the heart <-- this may not work on slower machines
***Close all script/text/other programs with text input before running this.
This program can be highly destructive if notepad is not launched for some reason.
Use it at your own risk.***
*/

#include <string.h>

int ledPin = 11;
int i,j,k;
int nBeats = 5; //no of beats
int fHigh = 14; // max font size
int fLow = 6; //min font size
int nSpaces = 20; // times to move the art to right
int cn[] ={0,0,0,0,0}; //to store count of each char in the set to be replaced back
char *rc[]= {"_"," ","I","Love","You"}; // replaced char set in original ascii art
char *rw[] ={"66","99","1","4","3"}; // replaced with this char set to obfuscate it
char *line[] = {"999999999999999999#991994999999999999999999999999#99199499",
  "999999999999#991994993..99999999999999#991994993...#",
  "99999999#991994993...#99199999999#991994993...#99199",
  "999999#991994993...#991994993...#9966666666666666#99199",
  "9999#991994993...#991994993...#99666666666666666666#99199",
  "99#991994993...#991994993...#99199Lo66666666666666#99199",
  "99#991994993...#991994993...#99199499Y666666666666#",
  "#991994993...#991994993...#991994993..6666#991",
  "#991994993...#991994993...#991994993...#9966#",
  "#991994993...#991994993...#991994993...#99199",
  "#991994993...#991994993...#991994993...#99199",
  "99#991994993...#991994993...#991994993...#99",
  "9999#991994993...#991994993...#991994993...",
  "99999999#991994993...#991994993...#991994993",
  "999999999999#991994993...#991994993...#99199Lov",
  "999999999999999999#991994993...#991994993...#",
  "999999999999999999999999#991994993...#99199499Y",
  "9999999999999999999999999999#991994993...#99199L",
  "9999999999999999999999999999999999#991994993.",
  "99999999999999999999999999999999999999#99199499",
  "999999999999999999999999999999999999999999#99199Lo",
  "99999999999999999999999999999999999999999999#99199",
  "9999999999999999999999999999999999999999999999#99"}; // ascii art to be printed

void setup(){
  pinMode(ledPin, OUTPUT); //set led
  delay(2000); // not needed
}


void loop () {
  delay(2000); //wait until hid is detected
  digitalWrite(ledPin, HIGH); //turn led on
  WriteMessage();//main funtion
  KeyCombo(MODIFIERKEY_CTRL,KEY_END); // just in case if the font change function fails, this will not destroy the printed ascii
  KeyPress(KEY_ENTER);
  delay(2000);//let them watch it for couple of seconds
  for(j=1;j<=nBeats;j++){ // make heart beat by changing font size
    Beat(); //this will not work on slower machines.
  }
  ChFont(10); //set back the font size to default 10
  digitalWrite(ledPin, LOW); //tunr led off, we are done
  delay(50000); // delays the loop
}

void WriteMessage(){

  runcmd("notepad.exe"); //open notepad in cmd line
  delay(2000); //wait until note pad is open
  sysMenu(KEY_X); //maximize note pad
  delay(1000); //wait until the command is finished
  ChFont(10); //set the font size to default 10

  for(i=0;i<sizeof(line)/sizeof(line[0]);i++){ //loop through all lines of art
   for(j=0;line[i][j] != '\0';j++){
     
     if(line[i][j] == rw[0][0]){cn[0]++;} //count each char to be replaced
     if(line[i][j] == rw[1][0]){cn[1]++;}
     if(line[i][j] == rw[2][0]){cn[2]++;}
     if(line[i][j] == rw[3][0]){cn[3]++;}
     if(line[i][j] == rw[4][0]){cn[4]++;}
     
     Keyboard.print(line[i][j]); //print each char letter by letter
     delay(20);//this produces something to stare on screen
    }
    
    KeyPress(KEY_ENTER); //new line
    
  }

 for(i=0; i<nSpaces; i++){ //move the whole art to the right, more like to the center of notepad
   KeyCombo(MODIFIERKEY_CTRL,KEY_HOME);
   for(j=0;j<sizeof(line)/sizeof(line[0]);j++){ //move one line at a time and loop through all.
     KeyPress(KEY_SPACE);
     //delay(50);
     KeyPress(KEY_DOWN);
     KeyPress(KEY_HOME);
   }
 }
  
    for(i=0;i<sizeof(rw)/sizeof(rw[0]);i++){ //replace char one by one
    
    KeyCombo(MODIFIERKEY_CTRL,KEY_HOME);
    KeyCombo(MODIFIERKEY_CTRL,KEY_H);
    delay(300);
    sysMenu(KEY_M);
    delay(300); //these are important delays
    ClicknMove(-127,127); //moves replace screen to bottom left end and takes it out of way
    delay(300); //these are important delays to make click work
    
    switch(i){ //replace accordingly
      case 0:
    Keyboard.print(rw[0]);
    KeyPress(KEY_TAB);
    Keyboard.print(rc[0]);
    for(j=1;j < cn[0]/2 -5;j++){ //replace char by char but go few less
      KeyCombo(MODIFIERKEY_ALT,KEY_R);
      delay(100); //delay to stare at the action
    }
    break;
    case 1:
    Keyboard.print(rw[1]);
    KeyPress(KEY_TAB);
    Keyboard.print(rc[1]);
    for(j=1;j < (cn[1]/2 -5);j++){
      KeyCombo(MODIFIERKEY_ALT,KEY_R);
      delay(30);
    }
    break;
    case 2:
    Keyboard.print(rw[2]);
    KeyPress(KEY_TAB);
    Keyboard.print(rc[2]);
    for(j=1;j < cn[2] -5;j++){
      KeyCombo(MODIFIERKEY_ALT,KEY_R);
      delay(70);
    }
    break;
    case 3:
    Keyboard.print(rw[3]);
    KeyPress(KEY_TAB);
    Keyboard.print(rc[3]);
    for(j=1;j < (cn[3] -5);j++){
      KeyCombo(MODIFIERKEY_ALT,KEY_R);
      delay(70);
    }
    break;
    case 4:
    Keyboard.print(rw[4]);
    KeyPress(KEY_TAB);
    Keyboard.print(rc[4]);
    for(j=1;j < (cn[4] -5);j++){
      KeyCombo(MODIFIERKEY_ALT,KEY_R);
      delay(70);
    }
    break;
    
    }
    
      
    KeyCombo(MODIFIERKEY_ALT, KEY_A); //replace remaining few with replace all
    delay(30); // important for above command to be finished.
    sysMenu(KEY_C); //close replace box.
 } 
    
 }

void Beat(){
  
    for(i=6;i<=fHigh;i++){//increase font one size at a time
      ChFont(i);
      delay(20);
    }
    for(k=14;k>=fLow;--k){ //decrease font one size at a time
      ChFont(k);
      delay(20);
    }
   
}

void runcmd(char *cmd){
  KeyCombo(MODIFIERKEY_GUI,KEY_R); // open run dialog
  delay(1500); // wait for it to open
  Keyboard.print(cmd); // enter some command
  KeyPress(KEY_ENTER); // exec some command
}

void KeyPress(int SomeKey) {
  Keyboard.set_key1(SomeKey); // set some key
  Keyboard.send_now(); // "press" some key
  // clear some key
  Keyboard.set_key1(0);
  Keyboard.send_now();
}

void KeyCombo(int ModKey,int SomeKey) {
  Keyboard.set_modifier(ModKey); //set one or more modifier keys
  Keyboard.set_key1(SomeKey); // set regular key
  Keyboard.send_now(); // send strokes
  // clear keys
  Keyboard.set_modifier(0); // prep release of control keys
  Keyboard.set_key1(0); // have to do this to keep it from hitting key multiple times.
  Keyboard.send_now();
}

void sysMenu(int SomeKey) {
  Keyboard.set_modifier(MODIFIERKEY_ALT); //set one or more modifier keys
  Keyboard.set_key1(KEY_SPACE); // set regular key
  Keyboard.send_now(); // send strokes
  // clear keys
  Keyboard.set_modifier(0); // prep release of control keys
  Keyboard.set_key1(0); // have to do this to keep it from hitting key multiple times.
  Keyboard.send_now();
  delay(10);
  Keyboard.set_key1(SomeKey);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.send_now();
}
void ClicknMove(int x, int y){
   Mouse.set_buttons(1,0,0);
   Mouse.move(x, y);
     
  Mouse.set_buttons(0,0,0);
}
void ChFont(int sz){
 KeyCombo(MODIFIERKEY_ALT,KEY_O);
 delay(50); //magic number that works on my machine
 KeyPress(KEY_F); //open font window
 delay(50);
 KeyPress(KEY_TAB);//go to font size
 KeyPress(KEY_TAB);//go to font size
 Keyboard.print(sz);//give new size
 KeyPress(KEY_ENTER);
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...