Permalink
Browse files

Added Bended and dev sketches

  • Loading branch information...
pictux committed Oct 3, 2012
1 parent 512d739 commit fedabdea4ca251b75fe10c90debf1c396dd4a94a
Showing with 529 additions and 1 deletion.
  1. +187 −0 Rome/Bender/Bender.ino
  2. +1 −1 Rome/TweetYourMusic/TweetYourMusic.ino
  3. +122 −0 Rome/dev/postTweet/postTweet.ino
  4. +219 −0 Rome/dev/readTweet/readTweet.ino
View
@@ -0,0 +1,187 @@
+/*
+ Bender
+ Show me the way to the next whisky bar
+
+ Developed by Antonio / Luisa / Danilo / Yuri during
+ Arduinotour 2012 @ Rome
+*/
+
+
+int sensorPinSX = A0;
+int sensorPinC = A1;
+int sensorPinDX = A2;
+
+const int motor1Pin = 9;
+const int motor2Pin = 10;
+
+int speedMotor01 = 80;
+int speedMotor02 = 80;
+
+int sensorValueSX = 0;
+int sensorValueC = 0;
+int sensorValueDX = 0;
+
+int zeroValueSX;
+int zeroValueDX;
+int unoValueC;
+
+int ledPin1 = 3;
+int ledPin2 = 4;
+
+int alcoolSXPin = 7;
+int alcoolDXPin = 8;
+
+int alcoolValueSX=0;
+int alcoolValueDX=0;
+
+int alcoolSXOut = 5;
+int alcoolDXOut = 6;
+
+//Se modalit == 0 segue la striscia bianca e si ferma in prossimita' di un incrocio
+//Se modalit == 1 impazzisce, va sempre dritto e curva dal lato in cui rileva alcool
+int modalit = 0;
+
+
+void setup() {
+
+ Serial.begin(9600);
+
+ pinMode(ledPin1, OUTPUT);
+ digitalWrite(ledPin1, HIGH);
+
+ pinMode(ledPin2, OUTPUT);
+ digitalWrite(ledPin2, HIGH);
+
+ pinMode(alcoolDXPin, OUTPUT);
+ digitalWrite(alcoolDXPin, HIGH);
+
+ pinMode(alcoolSXPin, OUTPUT);
+ digitalWrite(alcoolSXPin, HIGH);
+
+ pinMode(alcoolSXOut, INPUT);
+ pinMode(alcoolDXOut, INPUT);
+
+ pinMode(motor1Pin, OUTPUT);
+ pinMode(motor2Pin, OUTPUT);
+
+ delay(2000);
+
+ //Prima di partire setta i valori relativi allo zero e all'uno
+ inizializza();
+
+}
+
+void loop() {
+
+ if(modalit==0){
+
+ analogWrite(motor1Pin, speedMotor01);
+ analogWrite(motor2Pin, speedMotor02);
+
+ sensorValueDX = analogRead(sensorPinDX);
+ sensorValueC = analogRead(sensorPinC);
+ sensorValueSX = analogRead(sensorPinSX);
+
+
+ alcoolValueSX = digitalRead(alcoolSXOut);
+ alcoolValueDX = digitalRead(alcoolDXOut);
+
+ sensorValueDX = map(sensorValueDX, 450, 900, 0, 255);
+ sensorValueC = map(sensorValueC, 500, 885, 0, 255);
+ sensorValueSX = map(sensorValueSX, 450, 900, 0, 255);
+
+ //come andare dritto
+ if(abs(unoValueC-sensorValueC)>40 ){
+ //caso in cui sta uscendo dal binario centrale
+ if(abs(zeroValueSX-sensorValueSX)>25){
+ //se sta uscendo verso sinista
+ // Serial.println("\t Stai uscendo verso sinistra");
+ speedMotor01 = 67;
+ speedMotor02 = 80;
+ }
+ else if(abs(zeroValueDX-sensorValueDX)>15){
+ //se sta uscendo verso destra
+ // Serial.println("\t Stai uscendo verso destra");
+ speedMotor01 = 80;
+ speedMotor02 = 67;
+ }
+ }
+ else {
+ // Serial.println("\t Vado drittooo!!!!");
+ speedMotor01 = 80;
+ speedMotor02 = 80;
+
+ }
+
+ if((abs(sensorValueC-250)<20)&&(abs(sensorValueSX-109)<20)&&(abs(sensorValueDX-180)<20)) {
+ //sono in prossimita' di un incrocio, blocco le ruote
+ speedMotor01 = 0;
+ speedMotor02 = 0;
+ analogWrite(motor1Pin, speedMotor01);
+ analogWrite(motor2Pin, speedMotor02);
+
+ while(true){
+ //mi metto in attesa di alcool, se lo rilevo effettuo la curva e riprendo a seguire il binario
+ alcoolValueSX = digitalRead(alcoolSXOut);
+ alcoolValueDX = digitalRead(alcoolDXOut);
+ if(alcoolValueSX==1){
+ speedMotor01 = 80;
+ analogWrite(motor1Pin, speedMotor01);
+ modalit=1;
+ delay(1500);
+ speedMotor02 = 80;
+ analogWrite(motor2Pin, speedMotor02);
+ break;
+ }
+ if(alcoolValueDX==1){
+ speedMotor02 = 80;
+ analogWrite(motor2Pin, speedMotor02);
+ delay(1500);
+ speedMotor01 = 80;
+ analogWrite(motor1Pin, speedMotor01);
+ modalit=1;
+ break;
+ }
+ delay(100);
+ }
+ }
+ }
+ else {
+ //modalita' impazzisce e va alla ricerca di alcool
+ speedMotor01 = 160;
+ speedMotor02 = 160;
+ analogWrite(motor1Pin, speedMotor01);
+ analogWrite(motor2Pin, speedMotor02);
+
+ alcoolValueSX = digitalRead(alcoolSXOut);
+ alcoolValueDX = digitalRead(alcoolDXOut);
+ if(alcoolValueSX==1){
+ speedMotor01 = 80;
+ analogWrite(motor1Pin, speedMotor01);
+ delay(1500);
+ speedMotor02 = 80;
+ analogWrite(motor2Pin, speedMotor02);
+ }
+ if(alcoolValueDX==1){
+ speedMotor02 = 80;
+ analogWrite(motor2Pin, speedMotor02);
+ delay(1500);
+ speedMotor01 = 80;
+ analogWrite(motor1Pin, speedMotor01);
+ }
+ }
+ delay(50);
+}
+
+void inizializza(){
+
+ sensorValueDX = analogRead(sensorPinDX);
+ sensorValueC = analogRead(sensorPinC);
+ sensorValueSX = analogRead(sensorPinSX);
+
+ zeroValueDX = map(sensorValueDX, 450, 900, 0, 255);
+ unoValueC = map(sensorValueC, 400, 885, 0, 255);
+ zeroValueSX = map(sensorValueSX, 400, 900, 0, 255);
+
+}
+
@@ -35,7 +35,7 @@ int ledB = 5;
int speaker = 9;
Tone tone1;
- q
+
//wired
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
@@ -0,0 +1,122 @@
+/*
+ Arduinotour 2012 @ Rome
+
+ Basic example of Twitter post, by pitusso
+
+ Twitter library:
+ http://arduino.cc/playground/Code/TwitterLibrary
+ updated following this post:
+ http://arduino.cc/forum/index.php?topic=121483.0
+ Wifi shield Arduino library:
+ http://arduino.cc/en/uploads/Main/WiFiShield_library.zip
+*/
+
+
+#include <SPI.h>
+#include <WiFi.h>
+#include <Twitter.h>
+
+char ssid[] = "ssid";
+char pass[] = "pwd";
+
+// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/ ; following token is for ArduinoTX)
+Twitter twitter("853399658-NYlyikic5XuHE1QKD1bAT8RkWN833QD1zA2vFzKa");
+
+String msgStrBase = "#hashtag ";
+String msgStr = "";
+char msgChar[50];
+
+int status = WL_IDLE_STATUS; // status of the wifi connection
+
+const int buttonPin = 2;
+
+// Variables will change:
+int buttonPushCounter = 0; // counter for the number of button presses
+int buttonState = 0; // current state of the button
+int lastButtonState = 0; // previous state of the button
+
+// initialize the library instance:
+WiFiClient client;
+
+void setup()
+{
+ Serial.begin(9600);
+
+ // initialize the button pin as a input:
+ pinMode(buttonPin, INPUT);
+
+ // check for the presence of the shield:
+ if (WiFi.status() == WL_NO_SHIELD) {
+ Serial.println("WiFi shield not present");
+ // don't continue:
+ while(true);
+ }
+
+ // attempt to connect to Wifi network:
+ while ( status != WL_CONNECTED) {
+ Serial.print("Attempting to connect to SSID: ");
+ Serial.println(ssid);
+ // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
+ status = WiFi.begin(ssid, pass);
+
+ // wait 10 seconds for connection:
+ delay(10000);
+ }
+
+ Serial.println("Ready ...");
+}
+
+void loop()
+{
+ // read the pushbutton input pin:
+ buttonState = digitalRead(buttonPin);
+
+ // compare the buttonState to its previous state
+ if (buttonState != lastButtonState) {
+ // if the state has changed, increment the counter
+ if (buttonState == HIGH) {
+
+ //TEST STRING
+
+ //create the string with sensors value
+ // read the analog sensor:
+ int sensorReading = analogRead(A0);
+
+ msgStr = msgStrBase;
+ msgStr += "s1=";
+ msgStr += sensorReading;
+
+ // you can append multiple readings to this String if your
+ // pachube feed is set up to handle multiple values:
+ int otherSensorReading = analogRead(A1);
+ msgStr += ",s2=";
+ msgStr += otherSensorReading;
+
+ msgStr = msgStr + ",i=" + buttonPushCounter;
+ msgStr.toCharArray(msgChar, 50);
+
+ tweetMsg(msgChar);
+ buttonPushCounter++;
+ }
+ }
+ // save the current state as the last state,
+ //for next time through the loop
+ lastButtonState = buttonState;
+}
+
+void tweetMsg(char *msg) {
+ if (twitter.post(msg)) {
+ // Specify &Serial to output received response to Serial.
+ // If no output is required, you can just omit the argument, e.g.
+ // int status = twitter.wait();
+ int status = twitter.wait(&Serial);
+ if (status == 200) {
+ Serial.println("OK.");
+ } else {
+ Serial.print("failed : code ");
+ Serial.println(status);
+ }
+ } else {
+ Serial.println("sending failed.");
+ }
+}
Oops, something went wrong.

0 comments on commit fedabde

Please sign in to comment.