Hi everyone,
I'm new to Arduino and as a really basic project I thought I'd try and produce something simple but fun. The idea is that you turn a pot which light up LEDs between 1 and 5 then you hit a button and it sends your rating to Twitter.
I'm stumbling on combining a random string with the rating, I'm not sure what the best way to do it is or how to mash up a string with an integer to create a pure string to send to Twitter.
Here's what I have so far.
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const int submitButtonPin = 9; // the number of the pushbutton pin
int ledPin[] = {2,3,4,5,6};
int ratingDial = A0;
int rating;
int i;
int ratingIn;
int submitButton = 0; // variable for reading the pushbutton status
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("my token goes in here");
// Message to post
char msg[] = {};
void setup() {
delay(1000);
Ethernet.begin(mac);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
// initialize the LED pin as an output:
for (i = 1; i < 5; i++) {
pinMode(ledPin[i], OUTPUT);
}
pinMode(submitButtonPin, INPUT);
}
void loop(){
submitButton = digitalRead(submitButtonPin);
ratingIn = analogRead(ratingDial);
rating = map(ratingIn, 0, 1024, 1, 6);
LEDrating();
if (submitButton == LOW) {
messageMaker(); // Create a random message with the rating in.
Serial.println(msg); // print the rating
submitted();
}
}
void LEDrating() {
for (i = 0; i < 5; i++){
digitalWrite(ledPin[i], LOW);
}
for (i = 0; i < rating; i++){
digitalWrite(ledPin[i], HIGH);
}
}
void submitted(){
//Send the rating to Twitter for the world to see.
Serial.println("connecting ...");
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("connection failed.");
}
// End of Twitter
for (i = 0; i < 5; i++){
digitalWrite(ledPin[i], LOW);
delay(50);
}
delay(100);
for (i = 0; i < 5; i++){
digitalWrite(ledPin[i], HIGH);
delay(50);
}
delay(100);
}
void messageMaker() {
String convertRating = String(rating);
msg = "One of our customers just rated us " && convertRating;
}