This shows you the differences between two versions of the page.
pm:prj2024:vstoica:rardu_marian.leanca [2024/05/27 03:45] radu_marian.leanca [Bibliografie/Resurse] |
pm:prj2024:vstoica:rardu_marian.leanca [2024/05/27 17:18] (current) radu_marian.leanca [Download] |
||
---|---|---|---|
Line 174: | Line 174: | ||
myDFPlayer.volume(30); // Set volume value (0~30). | myDFPlayer.volume(30); // Set volume value (0~30). | ||
- | // Set pin modes | + | // Set pin modes using direct register manipulation |
- | pinMode(trigPin, OUTPUT); | + | DDRB |= (1 << DDB1); // pumpPin (PB1/Pin 9) |
- | pinMode(echoPin, INPUT); | + | DDRD |= (1 << DDD7); // waterSensorPower (PD7/Pin 7) |
- | pinMode(waterSensorPower, OUTPUT); | + | DDRD |= (1 << DDD6); // soilMoisturePower (PD6/Pin 6) |
- | pinMode(soilMoisturePower, OUTPUT); | + | DDRB |= (1 << DDB0); // trigPin (PB0/Pin 8) |
- | pinMode(pumpPin, OUTPUT); | + | DDRB &= ~(1 << DDB1); // echoPin (PB1/Pin 9) |
analogWrite(pumpPin, 0); | analogWrite(pumpPin, 0); | ||
} | } | ||
Line 230: | Line 230: | ||
void measureDistance() { | void measureDistance() { | ||
// Clear the trigPin | // Clear the trigPin | ||
- | digitalWrite(trigPin, LOW); | + | PORTB &= ~(1 << PORTB0); |
delayMicroseconds(2); | delayMicroseconds(2); | ||
// Set the trigPin high for 10 microseconds | // Set the trigPin high for 10 microseconds | ||
- | digitalWrite(trigPin, HIGH); | + | PORTB |= (1 << PORTB0); |
delayMicroseconds(10); | delayMicroseconds(10); | ||
- | digitalWrite(trigPin, LOW); | + | PORTB &= ~(1 << PORTB0); |
// Read the echoPin and calculate the duration of the pulse | // Read the echoPin and calculate the duration of the pulse | ||
Line 247: | Line 247: | ||
void measureWaterLevel() { | void measureWaterLevel() { | ||
// Power on the water level sensor | // Power on the water level sensor | ||
- | digitalWrite(waterSensorPower, HIGH); | + | PORTD |= (1 << PORTD7); |
delay(10); | delay(10); | ||
Line 253: | Line 253: | ||
// Power off the water level sensor | // Power off the water level sensor | ||
- | digitalWrite(waterSensorPower, LOW); | + | PORTD &= ~(1 << PORTD7); |
} | } | ||
void measureSoilMoisture() { | void measureSoilMoisture() { | ||
// Power on the soil moisture sensor | // Power on the soil moisture sensor | ||
- | digitalWrite(soilMoisturePower, HIGH); | + | PORTD |= (1 << PORTD6); |
delay(10); | delay(10); | ||
Line 264: | Line 264: | ||
// Power off the soil moisture sensor | // Power off the soil moisture sensor | ||
- | digitalWrite(soilMoisturePower, LOW); | + | PORTD &= ~(1 << PORTD6); |
} | } | ||
- | |||
</code> | </code> | ||
Line 283: | Line 282: | ||
===== Download ===== | ===== Download ===== | ||
- | {{:pm:prj2024:vstoica:sswp.zip|}} | + | {{:pm:prj2024:vstoica:sswp_reg.zip|}} |
===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||
* Resurse Hardware: | * Resurse Hardware: |