Ce code permet d’allumer des boutons différents selon les couleurs et de combiner les couleurs si on les appuie en même temps
CODE:
#define GREEN 3
#define BLUE 5
#define RED 6
#define delayTime 20
void setup() {
Serial.begin(9600);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(RED, HIGH);
analogWrite( GREEN, 0);
analogWrite( BLUE, 0);
analogWrite( RED, 0);
}
//
//int redVal;
//int blueVal;
//int greenVal;
void loop() {
// RED ///////////////////////////////////////
// read the state of the pushbutton value:
int buttonState1 = digitalRead(8);
int buttonState2 = digitalRead(9);
int buttonState3 = digitalRead(10);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == LOW) {
// turn LED on:
analogWrite(RED, 255);
Serial.println(digitalRead(8));
} else {
// turn LED off:
analogWrite(RED, 0);
}
// BLUE ///////////////////////////////////////
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState2 == LOW) {
// turn LED on:
analogWrite(BLUE, 255);
Serial.println(digitalRead(10));
} else {
// turn LED off:
analogWrite(BLUE, 0);
}
// GREEN ///////////////////////////////////////
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState3 == LOW) {
// turn LED on:
analogWrite(GREEN, 255);
Serial.println(digitalRead(10));
} else {
// turn LED off:
analogWrite(GREEN, 0);
}
// int connect1 = digitalRead( 8 );
// int connect2 = digitalRead( 9 );
// int connect3 = digitalRead( 10 );
//Serial.println(connect2);
//Serial.println(connect3);
delay(1); // delay in between reads for stability
//
//
// int redVal = 255;
// int blueVal = 0;
// int greenVal = 0;
// for( int i = 0 ; i < 255 ; i += 1 ){
// greenVal += 1;
// redVal -= 1;
// analogWrite( GREEN, 255 – greenVal );
// analogWrite( RED, 255 – redVal );
//
// delay( delayTime );
// }
//
// redVal = 0;
// blueVal = 0;
// greenVal = 255;
// for( int i = 0 ; i < 255 ; i += 1 ){
// blueVal += 1;
// greenVal -= 1;
// analogWrite( BLUE, 255 – blueVal );
// analogWrite( GREEN, 255 – greenVal );
//
// delay( delayTime );
// }
//
// redVal = 0;
// blueVal = 255;
// greenVal = 0;
// for( int i = 0 ; i < 255 ; i += 1 ){
// redVal += 1;
// blueVal -= 1;
// analogWrite( RED, 255 – redVal );
// analogWrite( BLUE, 255 – blueVal );
//
// delay( delayTime );
// }
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
premier pas bouton couleurs from Studio Objet Augmente on Vimeo.
http://essai bouton couleurs from Studio Objet Augmente on Vimeo.
essai bouton couleurs dans maquettes from Studio Objet Augmente on Vimeo.
kaleidoscope disco from Studio Objet Augmente on Vimeo.