Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Delay a pin state after event on: July 18, 2014, 05:48:38 pm
If your willing to share I would like to see the 2nd option.

 Thanks
2  Using Arduino / Programming Questions / Re: Delay a pin state after event on: July 18, 2014, 04:12:55 pm
Thanks, I will try and write a piece of code using that structure and see what happens.

3  Using Arduino / Programming Questions / Re: Delay a pin state after event on: July 18, 2014, 03:30:58 pm
I am needing a 1000ms (1sec) delay from  the  time I receive the trigger form the scope until the relay de energizes. I am using this to control an old power system that requires you to press a button after discharge. I am just using 1 second as a buffer +- a few ms should not hurt.

 I am trying to use millis() but do not quite have it working right. I have posted a snippet that I am trying to learn from and adapt but it is not working out like I plan. If anyone can help me out I will sing and dance at your wedding.


Code:
void loop()
{
  if(digitalRead(switchPin) == LOW)
  {
     // here if the switch is pressed
     startTime = millis();
     while(digitalRead(switchPin) == LOW)
        ; // wait while the switch is still pressed
     long duration = millis() - startTime;
     Serial.println(duration);
  }
}
4  Using Arduino / Programming Questions / Delay a pin state after event on: July 18, 2014, 01:09:33 pm
First off any advice is appreciated.

 What I am trying to do is use my Oscopes trigger to control a relay, and have that part working fine. But, I need a delay between the time the TTL signal is received and the output pin goes low( normally closed system).

 I have been searching for examples to point me in the right direction and was looking at MIllis, but am not sure that's what I am looking for.

 If anyone could steer me in the right direction I will sing at your wedding
(not literally)  smiley-grin
5  Using Arduino / Sensors / Arduino UNO and CUI encoder (SPI ) on: April 06, 2013, 07:47:44 am
Good Day ALL

   I am trying to interface an absolute encoder with the Arduino. I have never worked with SPI, I have read information and understand the concept. I am just unclear when it comes to setting the code up. I found an example that someone had posted for the encoders they were working with , so I took the code and tried modifying it to work with the CUI encoder but am a bit lost. Please lend me a hand if you can. Note the code may not make much sense as it has some pieces of the old code basically I added the pins for MOSI , MISO, and CS.  


Code:
const int PIN_CS = 4;
const int PIN_CLOCK = 13;
const int PIN_MOSI =11;
const int PIN_MISO = 12;

void setup() {
  Serial.begin(9600);
  pinMode(PIN_CS, OUTPUT);
  pinMode(PIN_CLOCK, OUTPUT);
  pinMode(PIN_MOSI, OUTPUT);
  pinMode(PIN_MISO, INPUT);

  digitalWrite(PIN_CLOCK, HIGH);
  digitalWrite(PIN_CS, LOW);
}


//byte stream[16];
void loop() {

  digitalWrite(PIN_CS, HIGH);
  digitalWrite(PIN_CS, LOW);
  int pos = 0;
  for (int i=0; i<10; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
    
    byte b = digitalRead(PIN_MOSI) == HIGH ? 1 : 0;
    pos += b * pow(2, 10-(i+1));
  }
  for (int i=0; i<6; i++) {
    digitalWrite(PIN_CLOCK, LOW);
    digitalWrite(PIN_CLOCK, HIGH);
  }
  digitalWrite(PIN_CLOCK, LOW);
  digitalWrite(PIN_CLOCK, HIGH);
  Serial.println(pos);
}  

 I appreciate any help/examples that you guys can offer.

  JH

 encoder
Code:
http://www.cui.com/Product/Components/Encoders/Absolute_Encoders/Modular/AMT203-V
Pages: [1]