mirror of
https://github.com/2martens/uni.git
synced 2026-05-07 03:46:25 +02:00
[ES-Blatt3] Finished 3.2
Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -3,11 +3,6 @@
|
|||||||
// these variables describe the used hardware pins
|
// these variables describe the used hardware pins
|
||||||
// adjust them when you use other pins
|
// adjust them when you use other pins
|
||||||
// hardware pins
|
// hardware pins
|
||||||
int az = 50;
|
|
||||||
|
|
||||||
int xout = A1;
|
|
||||||
int zout = A3;
|
|
||||||
int vref = A0;
|
|
||||||
|
|
||||||
// servo
|
// servo
|
||||||
int servoPin = 11;
|
int servoPin = 11;
|
||||||
@ -17,37 +12,16 @@ Servo ourServo;
|
|||||||
// don't touch them
|
// don't touch them
|
||||||
int rc = 1049999;
|
int rc = 1049999;
|
||||||
|
|
||||||
bool volatile read_ready = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup function for initial setup code
|
* Setup function for initial setup code
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
pmc_set_writeprotect(false);
|
|
||||||
pmc_enable_periph_clk(ID_TC0);
|
|
||||||
|
|
||||||
// configure hardware timer
|
|
||||||
TC_Configure(TC1, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK2) ;
|
|
||||||
TC_SetRC(TC1, 0, rc);
|
|
||||||
|
|
||||||
TC1->TC_CHANNEL[0].TC_IER=TC_IER_CPCS; // IER = interrupt enable register
|
|
||||||
TC1->TC_CHANNEL[0].TC_IDR=~TC_IER_CPCS;
|
|
||||||
|
|
||||||
NVIC_ClearPendingIRQ(TC1_IRQn);
|
|
||||||
NVIC_EnableIRQ(TC1_IRQn);
|
|
||||||
|
|
||||||
// start hardware timer
|
|
||||||
//TC_Start(TC0, 0);
|
|
||||||
|
|
||||||
// Configure servo
|
// Configure servo
|
||||||
ourServo.attach(servoPin);
|
ourServo.attach(servoPin);
|
||||||
ourServo.write(90);
|
ourServo.write(90);
|
||||||
|
|
||||||
pinMode(az, OUTPUT);
|
|
||||||
pinMode(servoPin, OUTPUT);
|
pinMode(servoPin, OUTPUT);
|
||||||
|
|
||||||
digitalWrite(az, HIGH);
|
|
||||||
|
|
||||||
// initialize serial port
|
// initialize serial port
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
}
|
}
|
||||||
@ -56,18 +30,19 @@ void setup() {
|
|||||||
* Loop function for main code
|
* Loop function for main code
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
for (int i = 0; i < 90; i++) {
|
for (int i = 90; i <= 180; ++i) {
|
||||||
ourServo.write(90 + i);
|
ourServo.write(i);
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
Serial.println(ourServo.read());
|
delay(1000);
|
||||||
|
for (int i = 180; i >= -180; --i) {
|
||||||
|
ourServo.write(i);
|
||||||
|
delay(10);
|
||||||
}
|
}
|
||||||
|
delay(1000);
|
||||||
/**
|
for (int i = -180; i <= 90; ++i) {
|
||||||
* Used to handle the timer.
|
ourServo.write(i);
|
||||||
*/
|
delay(10);
|
||||||
void TC1_Handler()
|
}
|
||||||
{
|
delay(2000);
|
||||||
// request static for some magic behind the curtain
|
|
||||||
TC_GetStatus(TC1, 0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user