Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Buy this case and you can shoot eye beams too!
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
crenn;295498 wrote: What code are you running currently?
// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7
#include <Servo.h>
#define CONTROL 7
Servo myservo; // create servo object to control a servo
int temps = 0; // analog pin used to connect the temp sensor
int val; // variable to read the value from the analog pin
void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object
digitalWrite(CONTROL, LOW); // ensure internal pullup resistor is disabled.
}
void loop()
{
val = digitalRead(CONTROL); //read input of pin 7 and store it
if (val == HIGH){ // reads whether or not 5v is present on pin 7, if 5v present, continue:
val = analogRead(temps); // reads the value of the temp sensor (value between 0 and 1023)
val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(25); // waits for the servo to get there
} else {
if (val == LOW); // if no voltage present on pin 7, continue
myservo.write(50); //sets servo position to 50 if no voltage is detected on pin 7
}
delay(25); // waits for the servo to get there
}
if (val == LOW); // if no voltage present on pin 7, continue
sum = (sum - (sum / 8)) + (analogRead (pin) / 8);
crenn;295605 wrote: Just beware it will still jitter (that's an issue with the code). However that will be solved in the next set of code I write.
EDIT: Note there is probably problems with this code (Acceptable since it's 3:48AM here currently) but this is roughly what is needed.
// Controlling a servo position using a temperature sensor // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> // edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7 // edited again 7-4-2010 by crenn to simplify the code a little // edited yet again 7-5-2010 by crenn to add features #include <Servo.h> Servo myservo; // create servo object to control a servo //Constants const unsigned char CONTROL = 7; // digital pin used to detect if the system is on or off const unsigned char temps = 0; // analogue pin used to connect the temp sensor const unsigned char MAX_VAL = 10; //Main global varibles char trigger = 0; // varible used to store the control pin value unsigned int val; // variable to read the value from the analog pin unsigned int updateAvgtemp(){ static int history[MAX_VAL]={0}; static unsigned char lastHist=0; static unsigned char numHist=0; unsigned int temp=0; unsigned char counter=0; unsigned char arcount=0; history[lastHist] = analogRead(temps); if(numHist<MAX_VAL) ++numHist; arcount=lastHist; ++lastHist; if(lastHist>=MAX_VAL) lastHist=0; temp=0; counter=0; do{ temp+=history[arcount]; arcount--; if(arcount>MAX_VAL) arcount=(MAX_VAL-1); counter++; }while(counter < numHist); return (temp/numHist); } void setup() { pinMode (CONTROL, INPUT); // sets the control pin to input myservo.attach(9); // attaches the servo on pin 9 to the servo object digitalWrite(CONTROL, LOW); // ensure internal pullup resistor is disabled. } void loop() { trigger = digitalRead(CONTROL); // read input of pin CONTROL and store it if (trigger == HIGH){ // reads if pin CONTROL, if true, do this: val = updateAvgtemp(); // read the value of the temp sensor (value with range of 1024) val = map(val, 350, 700, 75, 105); // scale it to use it with the servo (value between 75 and 105) myservo.write(val); // sets the servo position according to the scaled value } else { myservo.write(50); // sets servo position to 50 if above statment is false } delay(125); // wait 25ms for the servo to move to it's new position and also 100ms until it gets the new value }
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
msmrx57;296726 wrote: :eek: Farging AWESOME!!!!!!! That is sooooooo damn cool. 8) +rep for sure
crenn;296745 wrote: I want to see this in action! I'm also curious the radius of the arm (from pivot to connector) for each panel and the radius of the servo.... just curious!
Also you're welcome for the code, didn't take too long to write up and hopefully will work exactly how you want it to!
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
x88x;297163 wrote: Very nice. Looks like there's plenty of space for the larger servo too.
crenn;297177 wrote: How come you moved to a ball linkage if you mind me asking? I don't think that was in the original design.
OvRiDe;297181 wrote: Top notch my friend. Looking great! I can't wait to see it in action.
Oneslowz28;297188 wrote: Looking awesome! This is going to be one of the coolest PC + Arduino mods to date!
Please Log in or Create an account to join the conversation.
// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7
// edited again 7-4-2010 by crenn to simplify the code a little
// edited yet again 7-5-2010 by crenn to add features
// edited again 7-21-2010 by Will Lyon - recalibrated servo positions
#include <Servo.h>
Servo myservo; // create servo object to control a servo
//Constants
const unsigned char CONTROL = 7; // digital pin used to detect if the system is on or off
const unsigned char temps = 0; // analog pin used to connect the temp sensor
const unsigned char MAX_VAL = 10;
//Main global varibles
char trigger = 0; // varible used to store the control pin value
unsigned int val; // variable to read the value from the analog pin
unsigned int updateAvgtemp(){
static int history[MAX_VAL]={0};
static unsigned char lastHist=0;
static unsigned char numHist=0;
unsigned int temp=0;
unsigned char counter=0;
unsigned char arcount=0;
history[lastHist] = analogRead(temps);
if(numHist<MAX_VAL)
++numHist;
arcount=lastHist;
++lastHist;
if(lastHist>=MAX_VAL)
lastHist=0;
temp=0;
counter=0;
do{
temp+=history[arcount];
arcount--;
if(arcount>MAX_VAL)
arcount=(MAX_VAL-1);
counter++;
}while(counter < numHist);
return (temp/numHist);
}
void setup()
{
pinMode (CONTROL, INPUT); // sets the control pin to input
myservo.attach(9); // attaches the servo on pin 9 to the servo object
digitalWrite(CONTROL, LOW); // ensure internal pullup resistor is disabled.
}
void loop()
{
trigger = digitalRead(CONTROL); // read input of pin CONTROL and store it
if (trigger == HIGH){ // reads if pin CONTROL, if true, do this:
val = updateAvgtemp(); // read the value of the temp sensor (value with range of 1024)
val = map(val, 350, 700, 160, 80); // scale it to use it with the servo (value between 160 and 80)
myservo.write(val); // sets the servo position according to the scaled value
}
else {
myservo.write(180); // sets servo position to 180 if above statment is false
}
delay(125); // wait 25ms for the servo to move to it's new position and also 100ms until it gets the new value
}
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.