summaryrefslogtreecommitdiff
path: root/trunk/darwin/electronics/Arduino-Sanguino/pwm-driver/exerciser/exerciser.pde
blob: 144ce7e03982e8dc03776d1d7f2958421444a723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

int pwm_a = 9;
int pwm_b = 10;
int pwm_c = 11;
int i;

void setup()
{
	pinMode(pwm_a, OUTPUT);
	pinMode(pwm_b, OUTPUT);
	pinMode(pwm_c, OUTPUT);	

	Serial.begin(9600);
}

void loop()
{
	//
	//fade all channels up and down.
	//
	Serial.println("Fading all pwm channels up to max.");
	for (i=0; i<=255; i++)
	{
		analogWrite(pwm_a, i);
		analogWrite(pwm_b, i);
		analogWrite(pwm_c, i);
	
		delay(100);
	}
	
        Serial.println("All pwm channels at max.");
	delay(1000);
        Serial.println("Fading all channels to 0");
        
        for (i=255; i>=0; i--)
	{
		analogWrite(pwm_a, i);
		analogWrite(pwm_b, i);
		analogWrite(pwm_c, i);

		delay(100);	
	}

	Serial.println("All pwm channels at zero.");
        delay(1000);
	
        fade_channel(pwm_a);
        fade_channel(pwm_b);
        fade_channel(pwm_c);
}

void fade_channel(int channel)
{
	Serial.println("Fading pwm channel to max: ");
        Serial.println(channel);
                
	for (i=0; i<=255; i++)
	{
		analogWrite(pwm_a, i);
		delay(100);
	}

	Serial.println("pwm channel at max.");
        delay(1000);
        Serial.println("fading down.");
	
        for (i=255; i>=0; i--)
	{
		analogWrite(pwm_a, i);
		delay(100);	
	}

	Serial.println("pwm channel at 0.");
        delay(1000);
}