Go Down

Topic: Easy Question - How to set an attribute bit (Read 361 times) previous topic - next topic

sam

I have a sketch that polls the user for:
1. A time duration between 1 and 15 seconds.
2. The amount of that duration that digital pin 9 should be set high.
3. How many (up to 4) additional digital pins should be activated at that frequency.  These are pins 10-13.

What I want to do is to set each additional pin to either be synchronized with pin 9 or offset by the duration that pin 9 is HIGH.

I am trying to understand how I can set a "sync" bit for the additional channels.

Here is the function that I am hoping to have handle the selection of additional channels and whether or not to synchronize each to the master channel 9.  I am learning as I go so it may be convoluted and if you have to time to steer me in the right direction I am very willing to take criticism.  For what it's worth, here it is:




Code: [Select]
//
//
//Set Number of Channels
//
//
int setChannels(){
 int result;                                      // Variable to store return value
 do {
   potval = analogRead(potpin);                   // Read pot value (0 - 1023)
   mySerial.print("?x00?y0");                     // Cursor to column 0, line 0
   mySerial.print("Set Number of");
   mySerial.print("?x00?y1?l");                   // Cursor to column 0, line 1, clear line
   mySerial.print("Channels: ");
   potval = map(potval, 0, 1023, 5, 1);         // Scale pot value to 1 to 5 channels
   mySerial.print(potval);                        // Print pot value  

   buttonval = digitalRead(buttonpin);            // Check for button press
   /*
  If button is pressed & it wasn't being pressed a moment ago & its been long enough since the
    last time that it isn't a bounce... ...remember press time for next debounce?
    */
   if (buttonval == HIGH && prevbuttonval == LOW && millis() - presstime > debounce) {
     presstime = millis();                        // Store time button was pressed
     result = potval;                              // Store potval to cycle
     delay(1000);
     mySerial.print("?x00?y0?l");                 // Cursor to column 0, line 0, clear line        
     mySerial.print("Set Number of");  
     delay(2000);  
     mySerial.print("?f");                        // Clear the LCD      
     //     prevbuttonval = buttonval;

     // Set Channel Sync
     if(result > 1){
       for(int i = 2; i <= result; i++){               // Loop to set channel sync

         do {
           potval = analogRead(potpin);                   // Read pot value (0 - 1023)
           mySerial.print("?x00?y0Set Channel ");         // Cursor to column 0,line 0
           mySerial.print(i);                             // Print channel in question
           mySerial.print("?x00?y1?lSync.: ");             // Cursor to column 0, line 1, clear line

           if(potval <= 511) {
             mySerial.print("Yes");
           }
           else {
             mySerial.print("No");
           }
           buttonval = digitalRead(buttonpin);            // Check for button press
           /*
  If button is pressed & it wasn't being pressed a moment ago & its been long enough since the
            last time that it isn't a bounce... ...remember press time for next debounce?
            */
           if (buttonval == HIGH && prevbuttonval == LOW && millis() - presstime > debounce) {
             presstime = millis();                        // Store time button was pressed

             /*
     
              How to set sync bit?
             
              */
           }





           return result;
         }
         while (i <= result);
       }
     }
   }
 }
 while (1 == 1);
}



Thanks so much for any help.

Sam
I have never let my schooling interfere with my education.
~ Mark Twain

http://www.lewrockwell.com/

sam

I have never let my schooling interfere with my education.
~ Mark Twain

http://www.lewrockwell.com/

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy