Operácie

Acrob06: Rozdiel medzi revíziami

Z SensorWiki

 
Riadok 1: Riadok 1:
[[Acrob01|Predošlá úloha...]] | [[Acrob|Späť do menu]] | [[Acrob03|Pokračovanie...]]
+
Použijeme ten istý senzor ako v predošlej úlohe, len si ukážeme jeho využitie v digitálnom
 +
režime. Úlohu rozhodovacieho prvku za nás prevezme vstupný komparátor mikroprocesora.
 +
 
 +
Vyskúšajte tento program:
 +
 
 +
<source lang="c">
 +
#define LED_Yellow  13  // select the pin for the LED
 +
#define SENSOR  3
 +
 
 +
long val = 0;          // variable to store the value coming from the sensor
 +
 +
void setup()
 +
{
 +
  pinMode(LED_Yellow, OUTPUT);    // declare this pin as an OUTPUT
 +
  pinMode(SENSOR, INPUT);        // declare this pin as an INPUT
 +
 
 +
  Serial.begin(9600);
 +
 
 +
  Serial.println("Test started  \n");
 +
  digitalWrite(LED_Yellow, HIGH);  // make it visible
 +
  delay(1000);
 +
}
 +
 +
 
 +
void loop()
 +
{
 +
    val = digitalRead(SENSOR);    // read the value from the sensor
 +
    Serial.print("Sensor = "); 
 +
    Serial.println(val, BIN); 
 +
    delay(200);
 +
}  /* End of Loop */
 +
 
 +
</source>
 +
 
 +
 
 +
[[Acrob05|Predošlá úloha...]] | [[Acrob|Späť do menu]] | [[Acrob07|Pokračovanie...]]

Verzia zo dňa a času 21:23, 26. apríl 2010

Použijeme ten istý senzor ako v predošlej úlohe, len si ukážeme jeho využitie v digitálnom režime. Úlohu rozhodovacieho prvku za nás prevezme vstupný komparátor mikroprocesora.

Vyskúšajte tento program:

#define LED_Yellow  13   // select the pin for the LED
#define SENSOR  3

long val = 0;           // variable to store the value coming from the sensor
 
void setup() 
{ 
  pinMode(LED_Yellow, OUTPUT);    // declare this pin as an OUTPUT
  pinMode(SENSOR, INPUT);         // declare this pin as an INPUT

  Serial.begin(9600);

  Serial.println("Test started   \n");
  digitalWrite(LED_Yellow, HIGH);  // make it visible
  delay(1000);
} 
 

void loop() 
{ 
    val = digitalRead(SENSOR);     // read the value from the sensor
    Serial.print("Sensor = ");  
    Serial.println(val, BIN);  
    delay(200);
}   /* End of Loop */


Predošlá úloha... | Späť do menu | Pokračovanie...