Material Utilizado para o protótipo:
- Arduino
- Celular com Android e Internet.
- Shield Ethernet
- 3 LEDs nas cores Vermelha, Verde e Azul (RGB)
- Bateria de 9v
- Armação da Luminária
- Folha de Papel / Acrílico
Códigos Usados...
Nunca existiu uma grande inteligência sem uma veia de loucura. - Aristóteles
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /** * Controller LED RGB */ #define START_COLOR_CHAR '^' #define END_COLOR_CHAR '$' #define COLOR_SIZE 8 #define PIN_RED 9 #define PIN_GREEN 11 #define PIN_BLUE 10 char serialMessage[COLOR_SIZE]; unsigned int readChar; unsigned int count; unsigned long color; unsigned int r; unsigned int g; unsigned int b; boolean readingSerial; void setup() { Serial.begin(9600); readingSerial = false; } void loop() { if (Serial.available() > 0 && !readingSerial) { if (Serial.read() == START_COLOR_CHAR) { serialReadColor(); } } } void serialReadColor() { readingSerial = true; count = 0; iniReading: if (Serial.available() > 0) { readChar = Serial.read(); if (readChar == END_COLOR_CHAR || count == COLOR_SIZE) { goto endReading; } else { serialMessage[count++] = readChar; goto iniReading; } } goto iniReading; endReading: readingSerial = false; serialMessage[count] = '\0'; setColor(serialMessage); } void setColor(char* value) { // Convert Char* to Long color = atol(value); // Extract RGB r = color >> 16 & 0xFF; g = color >> 8 & 0xFF; b = color >> 0 & 0xFF; // Send values to analog pins analogWrite(PIN_RED, r); analogWrite(PIN_GREEN, g); analogWrite(PIN_BLUE, b); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 48 49 50 51 52 53 54 55 56 57 58 59 | /** * Controller LED RGB */ import processing.serial.*; Serial port; void setup() { size(100, 150); noStroke(); // Background colorMode(HSB, 100); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { stroke(i, j, 100); point(i, j); } } // Select port println(Serial.list()); port = new Serial(this, Serial.list()[1], 9600); } void draw() { // Only to enable the method mouseDragged } void mouseClicked() { processColor(); } void mouseDragged() { processColor(); } void processColor() { color c = get(mouseX, mouseY); noStroke(); fill(c); rect(0, 100, 100, 50); sendColorToSerial(c); } void sendColorToSerial(color colour) { // Get HEX String hexColor = hex(colour, 6); // Convert HEC to Number long numColor = unhex(hexColor); // Send color number to serial port port.write("^" + numColor + "$"); } |