Created
April 10, 2013 03:59
-
-
Save hilukasz/5351691 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
| #include <CapacitiveSensor.h> | |
| #include "Letter.h" | |
| #include "LetterSensor.h" | |
| #include "KeyboardPad.h" | |
| #include <Wire.h> | |
| const byte capSenseSend = 53; | |
| LetterSensor lsa (Letter('a'), capSenseSend, 22, 22); | |
| LetterSensor lsb (Letter('b'), capSenseSend, 23, 23); | |
| LetterSensor lsc (Letter('c'), capSenseSend, 24, 24); | |
| LetterSensor lsd (Letter('d'), capSenseSend, 25, 25); | |
| LetterSensor lse (Letter('e'), capSenseSend, 26, 26); | |
| LetterSensor lsf (Letter('f'), capSenseSend, 27, 27); | |
| LetterSensor lsg (Letter('g'), capSenseSend, 28, 28); | |
| LetterSensor lsh (Letter('h'), capSenseSend, 29, 29); | |
| LetterSensor lsi (Letter('i'), capSenseSend, 30, 51); | |
| LetterSensor lsj (Letter('j'), capSenseSend, 31, 31); | |
| LetterSensor lsk (Letter('k'), capSenseSend, 32, 32); | |
| LetterSensor lsl (Letter('l'), capSenseSend, 33, 33); | |
| LetterSensor lsm (Letter('m'), capSenseSend, 34, 34); | |
| LetterSensor lsn (Letter('n'), capSenseSend, 35, 35); | |
| LetterSensor lso (Letter('o'), capSenseSend, 36, 36); | |
| LetterSensor lsp (Letter('p'), capSenseSend, 37, 37); | |
| LetterSensor lsq (Letter('q'), capSenseSend, 38, 38); | |
| LetterSensor lsr (Letter('r'), capSenseSend, 39, 39); | |
| LetterSensor lss (Letter('s'), capSenseSend, 40, 40); | |
| LetterSensor lst (Letter('t'), capSenseSend, 41, 41); | |
| LetterSensor lsu (Letter('u'), capSenseSend, 42, 42); | |
| LetterSensor lsv (Letter('v'), capSenseSend, 43, 43); | |
| LetterSensor lsw (Letter('w'), capSenseSend, 44, 44); | |
| LetterSensor lsx (Letter('x'), capSenseSend, 45, 45); | |
| LetterSensor lsy (Letter('y'), capSenseSend, 46, 46); | |
| LetterSensor lsz (Letter('z'), capSenseSend, 47, 47); | |
| CapacitiveSensor cs_a = CapacitiveSensor(capSenseSend,22); | |
| CapacitiveSensor cs_b = CapacitiveSensor(capSenseSend,23); | |
| CapacitiveSensor cs_c = CapacitiveSensor(capSenseSend,24); | |
| CapacitiveSensor cs_d = CapacitiveSensor(capSenseSend,25); | |
| CapacitiveSensor cs_e = CapacitiveSensor(capSenseSend,26); | |
| CapacitiveSensor cs_f = CapacitiveSensor(capSenseSend,27); | |
| CapacitiveSensor cs_g = CapacitiveSensor(capSenseSend,28); | |
| CapacitiveSensor cs_h = CapacitiveSensor(capSenseSend,29); | |
| CapacitiveSensor cs_i = CapacitiveSensor(capSenseSend,30); | |
| CapacitiveSensor cs_j = CapacitiveSensor(capSenseSend,31); | |
| CapacitiveSensor cs_k = CapacitiveSensor(capSenseSend,32); | |
| CapacitiveSensor cs_l = CapacitiveSensor(capSenseSend,33); | |
| CapacitiveSensor cs_m = CapacitiveSensor(capSenseSend,34); | |
| CapacitiveSensor cs_n = CapacitiveSensor(capSenseSend,35); | |
| CapacitiveSensor cs_o = CapacitiveSensor(capSenseSend,36); | |
| CapacitiveSensor cs_p = CapacitiveSensor(capSenseSend,37); | |
| CapacitiveSensor cs_q = CapacitiveSensor(capSenseSend,38); | |
| CapacitiveSensor cs_r = CapacitiveSensor(capSenseSend,39); | |
| CapacitiveSensor cs_s = CapacitiveSensor(capSenseSend,40); | |
| CapacitiveSensor cs_t = CapacitiveSensor(capSenseSend,41); | |
| CapacitiveSensor cs_u = CapacitiveSensor(capSenseSend,42); | |
| CapacitiveSensor cs_v = CapacitiveSensor(capSenseSend,43); | |
| CapacitiveSensor cs_w = CapacitiveSensor(capSenseSend,44); | |
| CapacitiveSensor cs_x = CapacitiveSensor(capSenseSend,45); | |
| CapacitiveSensor cs_y = CapacitiveSensor(capSenseSend,46); | |
| CapacitiveSensor cs_z = CapacitiveSensor(capSenseSend,47); | |
| void setup(){ | |
| Serial.begin(9600); | |
| Serial1.begin(9600); | |
| delay(100); | |
| pinMode(13 ,OUTPUT); | |
| digitalWrite(13, LOW); | |
| Wire.begin(); | |
| } | |
| byte x = 0; | |
| void loop(){ | |
| // DEBUG | |
| /* | |
| Serial.print(" a: "); | |
| Serial.print(cs_a.capacitiveSensor(50)); | |
| Serial.print(" , b: "); | |
| Serial.print(cs_b.capacitiveSensor(50)); | |
| Serial.print(" , c: "); | |
| Serial.print(cs_c.capacitiveSensor(50)); | |
| Serial.print(" , d: "); | |
| Serial.print(cs_d.capacitiveSensor(50)); | |
| Serial.print(" , e: "); | |
| Serial.print(cs_e.capacitiveSensor(50)); | |
| Serial.print(" , f: "); | |
| Serial.print(cs_f.capacitiveSensor(50)); | |
| Serial.print(" , g: "); | |
| Serial.print(cs_g.capacitiveSensor(50)); | |
| Serial.print(" , h: "); | |
| Serial.print(cs_h.capacitiveSensor(50)); | |
| Serial.print(" , I: "); | |
| Serial.print(cs_i.capacitiveSensor(50)); | |
| Serial.print(" , J: "); | |
| Serial.print(cs_j.capacitiveSensor(50)); | |
| Serial.print(" , K: "); | |
| Serial.print(cs_k.capacitiveSensor(50)); | |
| Serial.print(" , L: "); | |
| Serial.print(cs_l.capacitiveSensor(50)); | |
| Serial.print(" , M: "); | |
| Serial.print(cs_m.capacitiveSensor(50)); | |
| Serial.print(" , N: "); | |
| Serial.print(cs_n.capacitiveSensor(50)); | |
| Serial.print(" , O: "); | |
| Serial.print(cs_o.capacitiveSensor(50)); | |
| Serial.print(" , P: "); | |
| Serial.print(cs_p.capacitiveSensor(50)); | |
| Serial.print(" , Q: "); | |
| Serial.print(cs_q.capacitiveSensor(50)); | |
| Serial.print(" , R: "); | |
| Serial.print(cs_r.capacitiveSensor(50)); | |
| Serial.print(" , S: "); | |
| Serial.print(cs_s.capacitiveSensor(50)); | |
| Serial.print(" , T: "); | |
| Serial.print(cs_t.capacitiveSensor(50)); | |
| Serial.print(" , U: "); | |
| Serial.print(cs_u.capacitiveSensor(50)); | |
| Serial.print(" , V: "); | |
| Serial.print(cs_v.capacitiveSensor(50)); | |
| Serial.print(" , W: "); | |
| Serial.print(cs_w.capacitiveSensor(50)); | |
| Serial.print(" , X: "); | |
| Serial.print(cs_x.capacitiveSensor(50)); | |
| Serial.print(" , Y: "); | |
| Serial.print(cs_y.capacitiveSensor(50)); | |
| Serial.print(" , Z"); | |
| Serial.println(cs_z.capacitiveSensor(50)); | |
| Serial.println(" ================================ "); | |
| */ | |
| delay(200); | |
| doLighting(lsa); | |
| doLighting(lsb); | |
| doLighting(lsc); | |
| doLighting(lsd); | |
| doLighting(lse); | |
| doLighting(lsf); | |
| doLighting(lsg); | |
| doLighting(lsh); | |
| doLighting(lsi); | |
| doLighting(lsj); | |
| doLighting(lsk); | |
| doLighting(lsl); | |
| doLighting(lsm); | |
| doLighting(lsn); | |
| doLighting(lso); | |
| doLighting(lsp); | |
| doLighting(lsq); | |
| doLighting(lsr); | |
| doLighting(lss); | |
| doLighting(lst); | |
| doLighting(lsu); | |
| doLighting(lsv); | |
| doLighting(lsw); | |
| doLighting(lsx); | |
| doLighting(lsy); | |
| doLighting(lsz); | |
| } | |
| void doLighting(LetterSensor &sensor){ | |
| byte tempLedPin = sensor.getLedPin(); | |
| sensor.read(); | |
| Letter l = sensor.getLetter(); | |
| if(l.isPressed()){ | |
| //Serial.print("PASSED : "); Serial.println(l.getChar()); | |
| // data structure: Data, Charecter(char), | |
| sendLedOn(tempLedPin); | |
| Serial.print("Data,"); | |
| delay(10); | |
| Serial.print(l.getChar()); | |
| Serial.write("test"); | |
| Serial.print("\n"); | |
| //Serial.println(l.getDelay()); | |
| //delay(1000); | |
| } else { | |
| digitalWrite(tempLedPin, LOW); | |
| } | |
| } | |
| void sendLedOn(int ledNumber){ | |
| Wire.beginTransmission(4); // transmit to device #4 | |
| Wire.write(ledNumber); // sends one byte | |
| Wire.endTransmission(); | |
| delay(500); | |
| } |
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
| #include <SoftPWM.h> | |
| #include <Wire.h> | |
| int ledPins[] = { 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 }; | |
| void setup() | |
| { | |
| // Initialize | |
| SoftPWMBegin(); | |
| Wire.begin(4); // join i2c bus with address #4 | |
| Wire.onReceive(receiveEvent); // register event | |
| Serial.begin(9600); | |
| for(int i = 0; i < sizeof(ledPins); i++){ // start serial for output | |
| pinMode(ledPins[i],OUTPUT); | |
| digitalWrite(ledPins[i], LOW); | |
| //SoftPWMSet(ledPins[i], 0); | |
| //SoftPWMSetFadeTime(ledPins[i], 500, 500); | |
| } | |
| } | |
| void loop(){ | |
| //onOfAllLeds(); | |
| //String data; | |
| int incomingByte = 0; | |
| if (Serial.available() > 0) { | |
| // read the incoming byte: | |
| incomingByte = Serial.read(); | |
| // say what you got: | |
| Serial.print("I received: "); | |
| Serial.println(incomingByte, DEC); | |
| } | |
| } | |
| void receiveEvent(int howMany) | |
| { | |
| // receive byte as an integer | |
| int x = Wire.read(); | |
| Serial.println(x); // print the integer | |
| turnOn(x); | |
| } | |
| void softPWM(int pinNumber){ | |
| // Turn on - set to 100% | |
| SoftPWMSetPercent(pinNumber, 100); | |
| // Wait for LED to turn on - you could do other tasks here | |
| delay(100); | |
| // Turn off - set to 0% | |
| SoftPWMSetPercent(pinNumber, 0); | |
| // Wait for LED to turn off | |
| delay(500); | |
| } | |
| void softFadeAllLeds() { | |
| for(int i = 0; i < sizeof(ledPins); i++){ | |
| softPWM(ledPins[i]); | |
| } | |
| } | |
| void orderedLedLoop() { | |
| int currentLeds[] = { 47, 45, 24, 43, 23, 35, 34 }; | |
| for(int i = 0; i < sizeof(currentLeds); i++){ | |
| softPWM(currentLeds[i]); | |
| } | |
| } | |
| void onOfAllLeds() { | |
| for(int i = 0; i < 26; i++){ | |
| digitalWrite(ledPins[i], HIGH); | |
| delay(1000); | |
| digitalWrite(ledPins[i], LOW); | |
| delay(500); | |
| } | |
| } | |
| void turnOn(int pinNumber) { | |
| digitalWrite(pinNumber, HIGH); | |
| delay(1000); | |
| digitalWrite(pinNumber, LOW); | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment