Advertisement
asselinpaul

ds_nokia_unlock pattern

Nov 1st, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.92 KB | None | 0 0
  1. More info at my blog: asselinpaul.posterous.com
  2.  
  3. #include "PCD8544.h"
  4.  
  5. int y1 = A0;
  6. int x2 = A1;
  7. int y2 = A2;
  8. int x1 = A3;
  9.  
  10. boolean point1;
  11. boolean point2;
  12. boolean point3;
  13. boolean point4;
  14. boolean point5;
  15.  
  16. boolean unlocked;
  17.  
  18. int i=0;
  19.  
  20.  
  21. // pin 7 - Serial clock out (SCLK)
  22. // pin 6 - Serial data out (DIN)
  23. // pin 5 - Data/Command select (D/C)
  24. // pin 4 - LCD chip select (CS)
  25. // pin 3 - LCD reset (RST)
  26. PCD8544 nokia = PCD8544(7, 6, 5, 4, 3);
  27.  
  28. // a bitmap of a 16x16 fruit icon
  29. static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
  30. 0x30, 0xf0, 0xf0, 0xf0, 0xf0, 0x30, 0xf8, 0xbe, 0x9f, 0xff, 0xf8, 0xc0, 0xc0, 0xc0, 0x80, 0x00,
  31. 0x20, 0x3c, 0x3f, 0x3f, 0x1f, 0x19, 0x1f, 0x7b, 0xfb, 0xfe, 0xfe, 0x07, 0x07, 0x07, 0x03, 0x00, };
  32. #define LOGO16_GLCD_HEIGHT 16
  33. #define LOGO16_GLCD_WIDTH  16
  34.  
  35. void setup(void) {
  36.  
  37. pinMode(11, OUTPUT);
  38. digitalWrite(11, HIGH);  
  39.  
  40.  
  41.   nokia.init();
  42.   // you can change the contrast around to adapt the display
  43.   // for the best viewing!
  44.   nokia.setContrast(50);
  45.   // turn all the pixels on (a handy test)
  46.   nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);
  47.   delay(500);
  48.   // back to normal
  49.   nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
  50.  
  51. }
  52.  
  53. int readX(){
  54.   pinMode(y1, INPUT);
  55.   pinMode(x2, OUTPUT);
  56.   pinMode(y2, INPUT);
  57.   pinMode(x1, OUTPUT);
  58.  
  59.   digitalWrite(x2, LOW);
  60.   digitalWrite(x1, HIGH);
  61.  
  62.   delay(5); //pause to allow lines to power up
  63.  
  64.   return analogRead(y1);
  65.   }
  66.  
  67.   int readY(){
  68.  
  69.   pinMode(y1, OUTPUT);
  70.   pinMode(x2, INPUT);
  71.   pinMode(y2, OUTPUT);
  72.   pinMode(x1, INPUT);
  73.  
  74.   digitalWrite(y1, LOW);
  75.   digitalWrite(y2, HIGH);
  76.  
  77.   delay(5); //pause to allow lines to power up
  78.  
  79.   return analogRead(x2);
  80. }
  81.  
  82. void loop (void) {
  83.  
  84.  
  85.  
  86.   int x = readX();
  87.   int y = readY();
  88.  
  89.  nokia.setCursor(0, 0);
  90.   nokia.print("Draw unlock");
  91.   nokia.setCursor(0, 10);
  92.   nokia.print("Pattern");
  93.   nokia.display();
  94.  
  95. if(x <= 970 & x >= 870 & y <= 250 & y >= 150 ){
  96. point1 = true;
  97. nokia.setCursor(0,25);
  98. nokia.print("Goto point 2");
  99.  
  100.    }
  101.  
  102. if(point1 == true){
  103.  i++;
  104.  nokia.setCursor(0,40);
  105.  nokia.print(i);
  106. }
  107.    
  108. if(point1 == true & x <= 200 & x >= 90 & y <= 930 & y >= 830){
  109.   point2 = true;
  110.  nokia.setCursor(0,25);
  111.  nokia.print("Goto point 3");
  112. }
  113.  
  114. if(point2 == true & x <= 165 & x >= 90 & y <= 250 & y >= 120){
  115.   point3 = true;
  116.  nokia.setCursor(0,25);
  117.  nokia.print("Goto point 4");
  118. }
  119.  
  120. if(point3 == true & x <= 999 & x >= 865 & y <= 950 & y >= 800){
  121.   point4 = true;
  122.  nokia.setCursor(0,25);
  123.  nokia.print("Goto point 5");
  124. }
  125.  
  126. if(point4 == true & x <= 970 & x >= 870 & y <= 250 & y >= 150){
  127.   point5 = true;
  128.   unlocked = true;
  129.   point1 = false;
  130.  nokia.clear();
  131.  nokia.setCursor(0,25);
  132.  nokia.print("Unlocked        ");
  133.  
  134. }
  135.  
  136. if(i >= 150){
  137.  point1 = false;
  138.  point2 = false;
  139.  point3 = false;
  140.  point4 = false;
  141.  point5 = false;
  142.  
  143.   nokia.setCursor(0,25);
  144.  nokia.print("Too slow!      ");
  145. }
  146.    
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement