Created
June 10, 2012 15:33
-
-
Save sash13/2906233 to your computer and use it in GitHub Desktop.
Кот ардуинки и сервачка на компе
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int pin1 = 8; | |
| const int pin2 = 7; | |
| const int pin3 = 6; | |
| const int pin4 = 5; | |
| const int pin6 = 4; | |
| const int pin7 = 3; | |
| const int pin9 = 2; | |
| const int ledPin = 13; | |
| int pin1m = 0; | |
| int pin2m = 0; | |
| int pin3m = 0; | |
| int pin4m = 0; | |
| int pin6m = 0; | |
| int pin7m = 0; | |
| int pin9m = 0; | |
| int sum = 0; | |
| void setup() { | |
| pinMode(pin1, INPUT); | |
| pinMode(pin2, INPUT); | |
| pinMode(pin3, INPUT); | |
| pinMode(pin4, INPUT); | |
| pinMode(pin6, INPUT); | |
| pinMode(pin7, OUTPUT); | |
| pinMode(pin9, INPUT); | |
| Serial.begin(9600); | |
| } | |
| void check(){ | |
| pin1m = digitalRead(pin1); | |
| pin2m = digitalRead(pin2); | |
| pin3m = digitalRead(pin3); | |
| pin4m = digitalRead(pin4); | |
| pin6m = digitalRead(pin6); | |
| pin7m = digitalRead(pin7); | |
| pin9m = digitalRead(pin9); | |
| if (pin7m == HIGH) { | |
| if (pin1m == LOW) { | |
| //Serial.println("u"); | |
| sum+=1; | |
| } | |
| if (pin2m == LOW) { | |
| //Serial.println("d"); | |
| sum+=2; | |
| } | |
| if (pin3m == LOW) { | |
| //Serial.println("l"); | |
| sum+=4; | |
| } | |
| if (pin4m == LOW) { | |
| //Serial.println("r"); | |
| sum+=8; | |
| } | |
| if (pin6m == LOW) { | |
| //Serial.println("B"); | |
| sum+=16; | |
| } | |
| if (pin9m == LOW) { | |
| //Serial.println("C"); | |
| sum+=32; | |
| } | |
| } | |
| if (pin7m == LOW) { | |
| if (pin6m == LOW ) { | |
| //Serial.println("A"); | |
| sum+=64; | |
| } | |
| if (pin9m == LOW && pin3m == LOW && pin4m == LOW) { | |
| //Serial.println("start"); | |
| sum+=128; | |
| } | |
| } | |
| } | |
| void loop(){ | |
| digitalWrite(pin7, LOW); | |
| check(); | |
| digitalWrite(pin7, HIGH); | |
| check(); | |
| Serial.println(sum, DEC); | |
| sum=0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import serial | |
| import virtkey | |
| import subprocess | |
| ser = serial.Serial('/dev/ttyUSB0') | |
| seg=[] | |
| old={'z':0, 'x':0, 'c':0, 'v':0, 'b':0, 'n':0,'1':0, 'KP_Enter':0, 'Up':0, 'Down':0, 'Left':0, 'Right':0} | |
| def click(old_bit, new_bit, key): | |
| if old_bit is 1 and new_bit is 0: | |
| press_os(key, 0) | |
| elif old_bit is 0 and new_bit is 1: | |
| press_os(key, 1) | |
| def click_l(old_bit, new_bit, key): | |
| if old_bit is 0 and new_bit is 1: | |
| subprocess.Popen(["xdotool", 'key', key]) | |
| def check(pos,bit): | |
| if pos is 4: | |
| try: | |
| click(old['z'], bit, 'z') | |
| except: | |
| pass | |
| elif pos is 5: | |
| try: | |
| click(old['x'], bit, 'x') | |
| except: | |
| pass | |
| elif pos is 6: | |
| try: | |
| click(old['c'], bit, 'c') | |
| except: | |
| pass | |
| elif pos is 7: | |
| try: | |
| click(old['KP_Enter'], bit, 'KP_Enter') | |
| except: | |
| pass | |
| elif pos is 0: | |
| try: | |
| click(old['Up'], bit, 'Up') | |
| except: | |
| pass | |
| elif pos is 1: | |
| try: | |
| click(old['Down'], bit, 'Down') | |
| except: | |
| pass | |
| elif pos is 2: | |
| try: | |
| click(old['Left'], bit, 'Left') | |
| except: | |
| pass | |
| elif pos is 3: | |
| try: | |
| click(old['Right'], bit, 'Right') | |
| except: | |
| pass | |
| elif pos is 8: | |
| try: | |
| click(old['v'], bit, 'v') | |
| except: | |
| pass | |
| elif pos is 9: | |
| try: | |
| click(old['b'], bit, 'b') | |
| except: | |
| pass | |
| elif pos is 10: | |
| try: | |
| click(old['n'], bit, 'n') | |
| except: | |
| pass | |
| elif pos is 11: | |
| try: | |
| click(old['1'], bit, '1') | |
| except: | |
| pass | |
| else: | |
| pass | |
| def func(num, pos): | |
| return (num & (1 << pos)) >> pos | |
| def press_os(key, byte): | |
| if byte: | |
| subprocess.Popen(["xdotool", 'keydown', key]) | |
| old[key] = 1 | |
| '''print 'press '+key''' | |
| else: | |
| subprocess.Popen(["xdotool", 'keyup', key]) | |
| old[key] =0 | |
| '''print 'up ' + key''' | |
| keyEmu = virtkey.virtkey() | |
| temp=[0]*12 | |
| while 1: | |
| s="".join(ser.readline().splitlines()) | |
| try: | |
| n=int(s) | |
| for pos in xrange(len(temp)): | |
| check(pos,func(n, pos)) | |
| except: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment