Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of project files

  • Loading branch information...
commit 514f9797775225df8a7f3b864691b35deb86511b 1 parent f8ec7d2
Zachary Parmley authored
View
113 arduino/recieve_display/recieve_display.ino
@@ -0,0 +1,113 @@
+#include <aJSON.h>
+// JSON TEST
+char* parseJson(char *jsonString) ;
+
+int redPin = 6;
+int greenPin = 5;
+int bluePin = 3;
+
+int incomingByte = 0; // for incoming serial data
+
+//const byte MAXIMUM_INPUT_LENGTH = 500;
+byte currentIndex = 0;
+char local_input[300];
+char endchar = '\n';
+char* screen_1;
+char* screen_2;
+int rgb[3] = {0, 0, 0};
+int i = 0;
+
+
+void setup() {
+ pinMode (redPin, OUTPUT); // Pino 3 declarado como saída
+ pinMode (bluePin, OUTPUT); // Pino 5 declarado como saída
+ pinMode (greenPin, OUTPUT); // Pino 6 declarado como saída
+ Serial.begin(9600);
+}
+
+void clearLed() {
+ analogWrite(redPin, 0);
+ analogWrite(greenPin, 0);
+ analogWrite(bluePin, 0);
+}
+
+void setLed(int l_rgb[3]) {
+ Serial.println("Setting lcd");
+ analogWrite(redPin, l_rgb[0]);
+ analogWrite(greenPin, l_rgb[1]);
+ analogWrite(bluePin, l_rgb[2]);
+}
+
+void setLcd(char* line1, char* line2) {
+ Serial.println(line1);
+ Serial.println(line2);
+}
+
+void loop() {
+ readSerialLine();
+}
+
+//void readSerialLine() {
+// if (Serial.available()) {
+// char local_input[MAXIMUM_INPUT_LENGTH+1] = {'\0'};
+// byte local_current_index = 0;
+// char nextchar = Serial.read();
+// char endchar = '\n';
+// while (nextchar != endchar){
+//// if (local_current_index>=MAXIMUM_INPUT_LENGTH){
+//// for (byte i=0; i<=MAXIMUM_INPUT_LENGTH; i++) {
+//// *local_input = '\0'; //clear input
+//// }
+//// local_current_index = 0; //start over
+//// }
+// local_input[local_current_index++] = nextchar;
+// nextchar = Serial.read();
+//// delay(200);
+// }
+// Serial.print("input is: ");
+// Serial.println(local_input);
+// parseJson(local_input);
+// }
+//}
+
+void readSerialLine() {
+ if (Serial.available()) {
+ int bytes_read = Serial.readBytesUntil(endchar, local_input, 300);
+ char return_buffer[bytes_read+1];
+ for (i=0; i<bytes_read; i++) {
+ return_buffer[i] = local_input[i];
+ }
+ return_buffer[i] = '\0';
+ i = 0;
+
+// Serial.println("input is: ");
+// Serial.println(return_buffer);
+ parseJson(return_buffer);
+ }
+}
+
+
+char* parseJson(char *jsonString) {
+ Serial.println(jsonString);
+ aJsonObject* root = aJson.parse(jsonString);
+ if (root != NULL) {
+ aJsonObject* color = aJson.getObjectItem(root, "rgb");
+ if (color != NULL) {
+ Serial.println("Color got it");
+ rgb[0] = color->child->valueint;
+ rgb[1] = color->child->next->valueint;
+ rgb[2] = color->child->next->next->valueint;
+ }
+
+ aJsonObject* screenobj = aJson.getObjectItem(root, "screen");
+ if (screenobj != NULL) {
+ Serial.println("Screen got it");
+ screen_1 = screenobj->child->valuestring;
+ screen_2 = screenobj->child->next->valuestring;
+ }
+ }
+ setLed(rgb);
+ setLcd(screen_1, screen_2);
+
+ aJson.deleteItem(root);
+}
View
14 python/CodeCompanionView.py
@@ -0,0 +1,14 @@
+import json
+
+class CodeCompanionView(object):
+ def __init__(self):
+ self.rgb = [0,0,0]
+ self.screen = ['', '']
+ self.id = 0
+ self.appstate = 0
+
+
+
+ @property
+ def json(self):
+ return json.dumps({'rgb': self.rgb, 'screen': [str(self.screen[0]).ljust(16, ' '), str(self.screen[1]).ljust(16, ' ')], 'id': self.id, 'appstate': self.appstate})
View
BIN  python/cc_messages.db
Binary file not shown
View
27 python/test_sendtoarduino.py
@@ -0,0 +1,27 @@
+import serial
+from CodeCompanionView import CodeCompanionView
+from random import randint
+
+view = CodeCompanionView()
+view.rgb = [randint(0,255),randint(0,255),randint(0,255)]
+view.screen = ['Heres hoping', 'this works']
+
+s = serial.Serial('/dev/tty.usbmodem1a1211', 9600)
+print '%s\n' % view.json
+s.write('%s\n' % view.json)
+# s.write("\n");
+
+
+#while 1:
+# print s.readline()
+
+
+
+# AKIAIOKVNDG55GOKRUUA
+# Hi6vk8DrKO1USRWZjEwiDUVUuo8BA7sREdXaQjFT
+
+# Friendly color 210 100 200
+
+ # String tryString = String(jsonString);
+ # tryString.replace("\\", "");
+ # jsonString = tryString.c_str();
Please sign in to comment.
Something went wrong with that request. Please try again.