Page 8 of 23 FirstFirst ... 34567891011121318 ... LastLast
Results 71 to 80 of 225

Thread: Project: Tempest SXR

  1. #71
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Project: Tempest SXR

    Code:
    // 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
    
    #include <Servo.h>
    
    Servo myservo;  // create servo object to control a servo
    
    const char CONTROL = 7;		// digital pin used to detect if the system is on or off
    const char temps = 0;		// analogue pin used to connect the temp sensor
    char trigger = 0;		// varible used to store the control pin value
    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()
    {
      trigger = digitalRead(CONTROL);	// read input of pin CONTROL  and store it
      if (trigger == HIGH){			// reads if pin CONTROL, if true, do this:
        val = analogRead(temps);		// 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
    }
    Try that code, I'll post a little bit later with code to do a moving window average.
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  2. #72
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Project: Tempest SXR

    I'll have to give that a shot later this afternoon or tomorrow. thanks!! +rep

  3. #73
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Project: Tempest SXR

    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.

    Code:
    // 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
    }
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  4. #74
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Project: Tempest SXR

    I went to upload that last one, and it popped up with "error: expected unqualified-id before numeric constant" on the "const unsigned char CONTROL = 7" line

    :EDIT: I deleted that line and it seems to work really well. it's just a TOUCH jittery when it moves, but that's fine. The issue I had was it jittering in one place lol

    hopefully I'll have my parts tomorrow, and I can get this thing built so I can hook it all up and test it. The jittering may go away when there's a slight load on the servo. If I lightly push it with my finger and put a load on it it seems to stop jittering

  5. #75
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Project: Tempest SXR

    Quote Originally Posted by SXRguyinMA View Post
    I went to upload that last one, and it popped up with "error: expected unqualified-id before numeric constant" on the "const unsigned char CONTROL = 7" line

    :EDIT: I deleted that line and it seems to work really well. it's just a TOUCH jittery when it moves, but that's fine. The issue I had was it jittering in one place lol

    hopefully I'll have my parts tomorrow, and I can get this thing built so I can hook it all up and test it. The jittering may go away when there's a slight load on the servo. If I lightly push it with my finger and put a load on it it seems to stop jittering
    I see why it had the error, I forgot to remove
    Code:
    #define CONTROL 7
    so it was seeing when it compiled
    Code:
    const unsigned char 7 = 7;
    which isn't what I wanted, the code will be update in 2 ticks to reflect that. Increase the number of samples to 20 (change MAX_VAL) and see if that helps.
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  6. #76
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Project: Tempest SXR

    works perfectly! +rep!

    :EDIT: need to spread some rep first lol

  7. #77
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Project: Tempest SXR

    Heh, fair enough. I just need to find a job where I can do this all day and get paid for it!
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  8. #78
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Project: Tempest SXR

    lol no kidding that'd be sweet

    oh a side note I got my first paying custom build coming up. It's for my brother-in-law. He wants to upgrade some of his stuff - new case, mobo, C2Q or i7, crossfire, etc. We're still throwing ideas around and working out details, but it'll be fun! It'll be a little tough being that I'm here in MA and he's out in St. Louis, but we'll get it figured out!

  9. #79
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Project: Tempest SXR

    Anyway, have all your problems been solved to your liking?
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  10. #80
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Project: Tempest SXR

    yes, it works perfectly. thank you!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •