A fairly simple one. I will only describe how the seek bar works, and part of how commands are recognized by arduino (arduino code). I will do another one about bluetooth another day.
[sourcecode language=”cpp”]
byte packet[2];
int pIndex;int rPin = 9;
int yPin = 10;
int gPin = 11;byte rValue = 0;
byte yValue = 0;
byte gValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// see if there’s incoming serial data:
if (Serial.available() > 0) {
packet[pIndex++] = Serial.read();
}
if(pIndex >= 2){
switch(packet[0]){
case ‘r’:
rValue = packet[1];
break;
case ‘y’:
yValue = packet[1];
break;
case ‘g’:
gValue = packet[1];
break;
default:
;
}
analogWrite(rPin, rValue); // 0 – 255
analogWrite(yPin, yValue);
analogWrite(gPin, gValue);
Serial.print(packet[0],);
Serial.print(" ");
Serial.println(packet[1]);
pIndex = 0;
}
delay(100);
}
[/sourcecode]
[sourcecode language=”java”]
SeekBar sr;
SeekBar sy;
SeekBar sg;
byte srValue;
byte syValue;
byte sgValue;
[/sourcecode]
[sourcecode language=”java”]
sr.setMax(255);
sy.setMax(255);
sg.setMax(255);
[/sourcecode]
[sourcecode language=”java”]
sr.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tv1.setText("Red " + progress);
srValue = (byte) progress;
}
public void onStopTrackingTouch(SeekBar seekBar) {
String temp = "r";
byte bytes[] = temp.getBytes();
try {
outputStream.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
try {
outputStream.write(srValue);
} catch (IOException e) {
e.printStackTrace();
}
}
});
[/sourcecode]
I don’t have the full source code anymore, but I have the sourcecode for the APP i used to control my hexapod robot, go to that post and scroll down to the bottom.
8 comments
complee code plz i will modify it for other purpose
might i have a preview of all of your code that you had for android base ?
i don’t have it anymore, it’s been a long time.
Hi Oscar,
I am working on developing an android app to communicate and read data (sensor readings) from an Arduino Uno board via a bluetooth module.
How can this be done?
Thank you.
yes it can be done.
Hey, can I have contact with you ? I want to learn this so much!!! Hope you can help!
Thanks
Hi, sure, just drop me a comment if you have any question.
Wait what is outputstream. Thats where i am stuck at!!