Cours:ShieldNano

De troyesGEII
Aller à : navigation, rechercher

Vérification du fonctionnement

Vous utiliserez le logiciel arduino pour vérifier le bon fonctionnement de votre carte électronique.

test du joystick (ou potentiomètres) et du capteur de température

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print("Temperature : ");
  Serial.print(voltage);
  Serial.println(" V");
  delay(1);
  sensorValue = analogRead(A1);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
   voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print("JoyStick Vertical : ");
  Serial.print(voltage);
  Serial.println(" V");
  delay(1);
  sensorValue = analogRead(A3);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
   voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print("JoyStick Horizontal : ");
  Serial.print(voltage);
  Serial.println(" V\n");
  delay(1000);
}

test des 2 leds et bps

/*
 * Test du fonctionnement des BP et Leds  
*/

unsigned char oldPush=255;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digitals pins as an output and input.
  DDRD = 0b00100000;
  DDRB = 0b00000001;
  Serial.begin(9600);
  Serial.println(PIND& 0b00001100);
}

// the loop function runs over and over again forever
void loop() {

  if((PIND & 0b00001100) != oldPush){  
    /**
     * Si les deux BP ne sont pas appuyés on fait clignoter les leds
     */
    if((PIND & 0b00000100)&&(PIND & 0b00001000))
    {
      while ((PIND & 0b00000100) && (PIND & 0b00001000))
      {
        PORTD |= 0b00100000;
        PORTB &= ~0b00000001;
        delay(250);
        PORTD &= ~0b00100000;
        PORTB |= 0b00000001;
        delay(250);    
      }
    }
  
    /**
     * Si on appuie sur le BP1 on allume la led 1
     */
    if(!(PIND & 0b00000100)) PORTD |= 0b00100000;
    else PORTD &= ~0b00100000;
   
    /**
     * Si on appuie sur le BP2 on allume la led 2
     */
    if(!(PIND & 0b00001000))  PORTB |= 0b00000001;
    else PORTB &= ~0b00000001;;
     
    delay(1);
    oldPush = PIND & 0b00001100;
    Serial.println(PIND & 0b00001100);
  }
}

test des leds 3 couleurs


Fichiers