EmperorPhoenix

Joystick Typing v0.1

Apr 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.68 KB | None | 0 0
  1. //ASCII
  2. //SPACE-32
  3. //UNDERSCORE-95
  4.  
  5. // include the library code:
  6. #include <LiquidCrystal.h>
  7. #include <IRremote.h>
  8.  
  9. IRsend irsend;
  10.  
  11. const int joy1X = 0;
  12. const int joy1Y = 2;
  13. const int joy2X = 4;
  14. const int joy2Y = 6;
  15.  
  16. // initialize the library with the numbers of the interface pins
  17. LiquidCrystal lcd(48, 49, 50, 51, 52, 53); //lcd(12, 11, 5, 4, 3, 2);
  18.  
  19. int qwe;
  20. int gloo;
  21. bool monom;
  22. char uSc=((char)95);
  23.  
  24. char mes[16];
  25.  
  26. void setup() {
  27.   qwe=0;
  28.   gloo=0;
  29.   monom=false;
  30.   // set up the LCD's number of columns and rows:
  31.   lcd.begin(16, 2);
  32.   // Print a message to the LCD.
  33.   Serial.begin(9600);
  34.   pinMode(7, INPUT);
  35.   pinMode(8, INPUT);
  36.   pinMode(9, INPUT);
  37.   mes[0]=uSc;
  38.   for(int q=1; q<16; q++){
  39.     mes[q]=(char)32;
  40.   }
  41. }
  42.  
  43.  
  44.  
  45.  
  46. void loop() {
  47.   lcd.clear();
  48.   // set the cursor to column 0, line 1
  49.   // (note: line 1 is the second row, since counting begins with 0):
  50.   lcd.setCursor(0, 1);
  51.   // print the number of seconds since reset:
  52.   lcd.print(mes);
  53.   lcd.setCursor(6,0);
  54.   lcd.print((int)analogRead(joy1X));
  55.   lcd.setCursor(12,0);
  56.   lcd.print((int)analogRead(joy1Y));
  57.   lcd.setCursor(0,0);
  58.   lcd.write(joyType());
  59.   //lcd.print(nunu);
  60.   delay(200);
  61.  
  62.   gloo++;
  63.   if(gloo%5==0){
  64.     monom=true;
  65.   }
  66.  
  67.   if(digitalRead(47)==HIGH){
  68.     sendMes();
  69.   }
  70.   if(digitalRead(46)==HIGH){
  71.     /*if(non==95){
  72.       mes[qwe]=(char)32;
  73.     }else{
  74.       mes[qwe]=nunu;
  75.     }*/
  76.     mes[qwe]=joyType();
  77.     mes[qwe+1]=uSc;
  78.     qwe++;
  79.   }
  80.   /*if(digitalRead(9)==HIGH){
  81.     mes[qwe]=' ';
  82.     mes[qwe+1]=uSc;
  83.     qwe++;
  84.   }*/
  85. }
  86.  
  87.   int joyLX;
  88.   int joyLY;
  89.   int joyRX;
  90.   int joyRY;
  91.  
  92.   int joyX;
  93.   int joyY;
  94.  
  95.  
  96. char joyType(){
  97.   joyY = analogRead(joy1X);
  98.   joyX = analogRead(joy1Y);
  99.  
  100.   int horizJoy;
  101.   int vertJoy = map(joyY, 192, 865, 2, -1);
  102.  
  103.   char joyC;
  104.  
  105.   char keyTop[] = {'q','w','e','r','t','y','u','i','o','p'};
  106.   char keyMid[] = {'a','s','d','f','g','h','j','k','l'};
  107.   char keyBot[] = {'z','x','c','v','b','n','m'};
  108.  
  109.   switch(vertJoy){
  110.     case 0:
  111.       horizJoy = map(joyX, 770, 180, 1, 10);
  112.       joyC = keyTop[horizJoy];
  113.       break;
  114.     case 1:
  115.       horizJoy = map(joyX, 770, 180, 1, 9);
  116.       joyC = keyMid[horizJoy];
  117.       break;
  118.     case 2:
  119.       horizJoy = map(joyX, 770, 180, 1, 7);
  120.       joyC = keyBot[horizJoy];
  121.       break;
  122.   }
  123.   return(joyC);
  124. }
  125.  
  126. void dualJoyType(){
  127.   joyLX = analogRead(0);
  128.   joyLY = analogRead(1);
  129.   joyRX = analogRead(2);
  130.   joyRY = analogRead(3);
  131.  
  132. //LEFT MAPPING
  133.   int horizL;
  134.   int vertL = map(joyLY, 200, 800, 0, 2);
  135.  
  136.   char leftC;
  137.  
  138.   char keyTopL[] = {'q','w','e','r','t'};
  139.   char keyMidL[] = {'a','s','d','f','g'};
  140.   char keyBotL[] = {'z','x','c','v'};
  141.  
  142.   switch(vertL){
  143.     case 0:
  144.       horizL = map(joyLX, 770, 180, 0, 5);
  145.       leftC = keyTopL[horizL];
  146.       break;
  147.     case 1:
  148.       horizL = map(joyLX, 770, 180, 0, 5);
  149.       leftC = keyMidL[horizL];
  150.       break;
  151.     case 2:
  152.       horizL = map(joyLX, 770, 180, 0, 4);
  153.       leftC = keyBotL[horizL];
  154.       break;
  155.   }
  156.  
  157. //RIGHT MAPPING
  158.   int horizR;
  159.   int vertR = map(joyRY, 192, 865, 0, 2);
  160.  
  161.   char rightC;
  162.  
  163.   char keyTopR[] = {'y','u','i','o','p'};
  164.   char keyMidR[] = {'g','h','j','k','l'};
  165.   char keyBotR[] = {'v','b','n','m'};
  166.  
  167.   switch(vertR){
  168.     case 0:
  169.       horizR = map(joyLX, 770, 180, 0, 5);
  170.       rightC = keyTopR[horizR];
  171.       break;
  172.     case 1:
  173.       horizR = map(joyLX, 770, 180, 0, 5);
  174.       rightC = keyMidR[horizR];
  175.       break;
  176.     case 2:
  177.       horizR = map(joyLX, 770, 180, 0, 4);
  178.       rightC = keyBotR[horizR];
  179.       break;
  180.   }
  181. }
  182.  
  183. void sendMes(){
  184.   for(int i=0; i<16; i++){
  185.     int msg = (int)(mes[i]);
  186.     Serial.println(msg);
  187.     irsend.sendSony(msg, 12);
  188.   }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment