Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. // pin definition
  2. int data_p[] = {0,1,2,3,4,5,6,7};
  3. int xclock_p = 8;
  4. int pclock_p = 9;
  5. int href_p = 10;
  6. int vsynch_p = 11;
  7. // not used int siod = 12;
  8. // not used int sioc = 13;
  9.  
  10. int lastPclock = 0;
  11. int pclock;
  12. int href;
  13. int vsynch;
  14. byte pixel;
  15.  
  16. void setup() {
  17.  
  18. Serial.begin(9600);
  19. Serial.println("started");
  20. // configure data pins as input
  21. for (int i = 0; i < 8; i++) {
  22. pinMode(data_p[i], INPUT);
  23. }
  24. // configure rest input pins
  25. pinMode(xclock_p, OUTPUT);
  26. pinMode(pclock_p, INPUT);
  27. pinMode(href_p, INPUT);
  28. pinMode(vsynch_p, INPUT);
  29.  
  30. }
  31.  
  32. int control = 0;
  33.  
  34. void loop() {
  35.  
  36. // just take one snapshot (307200 = 600 * 480) {{{
  37. if (control >= 307200) {
  38. return;
  39. }
  40. // }}}
  41.  
  42. digitalWrite(xclock_p, HIGH);
  43.  
  44. //Serial.println("clock written");
  45.  
  46. vsynch = digitalRead(vsynch_p);
  47. href = digitalRead(href_p);
  48. pclock = digitalRead(pclock_p);
  49.  
  50. if (vsynch == HIGH) return;
  51. if (href == LOW) return;
  52. if (!(lastPclock == HIGH && pclock == LOW)) {
  53. lastPclock = pclock;
  54. return;
  55. } else {
  56. lastPclock = pclock;
  57. }
  58.  
  59. pixel = readByteFromDataInput();
  60.  
  61. char s[10];
  62. sprintf(s, "%d ", pixel);
  63.  
  64. Serial.println(s);
  65.  
  66. if (control % 640 == 0) {
  67. Serial.println("");
  68. }
  69.  
  70. // just take one snapshot {{{
  71. control++;
  72. // }}}
  73.  
  74. if (control >= 307200) {
  75. Serial.println("finished");
  76. }
  77.  
  78. }
  79.  
  80. byte readByteFromDataInput() {
  81. byte result = 0;
  82. for (int i = 0; i < 8; i++) {
  83. result = result << 1 | digitalRead(data_p[i]);
  84. }
  85. return result;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement