Stefano,
I think the code below will do what you want:
int numMillisToDelayForOutput = 1000; int currMillis = 0; int prevMillis = 0; void setup() { Serial.begin( 9600 ); pinMode( A0, INPUT ); pinMode( A1, INPUT ); pinMode( A2, INPUT ); pinMode( 3, OUTPUT ); pinMode( 5, OUTPUT ); pinMode( 6, OUTPUT ); } void loop() { bool OutputToSerial = false; // Get current milli currMillis = millis(); // Check if you should output to serial if( ( currMillis - prevMillis ) < 0 ) { // Choose how to handle a roll over } else if( ( currMillis - prevMillis ) >= numMillisToDelayForOutput ) { // Set flag OutputToSerial = true; } // Update prev time prevMillis = currMillis; int R = map( analogRead( A2 ), 0, 1023, 0, 255 ); int G = map( analogRead( A0 ), 0, 1023, 0, 255 ); int B = map( analogRead( A1 ), 0, 1023, 0, 255 ); // If you it's time to output to serial if( OutputToSerial ) { // Output results to serial Serial.print( "R: " ); Serial.print( R ); Serial.print( "G: " ); Serial.print( G ); Serial.print( "B: " ); Serial.print( B ); } analogWrite( 6, R ); analogWrite( 3, G ); analogWrite( 5, B ); }
Essentially, you're using the millis() function to check whether enough time has elapsed to determine whether you should output to serial.