My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/*
* BlinkMuinoServoKnob -- Control a servo with a knob
*
*
*
* 2011 - Tod E. Kurt - http://todbot.com/blog/ - http://thingm.com/
*/

// BlinkM / BlinkM MinM pins
const int redPin = 3; //
const int grnPin = 4; //
const int bluPin = 1; // PWM, will blink when programming
const int sdaPin = 0; // PWM, 'd' pin, can be digital I/O
const int sclPin = 2; // A/D, 'c' pin, can be digital I/O, or analog input


const int servoPin = sdaPin;
const int knobPin = sclPin;

int pos;
int pulseWidth;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);

pinMode(servoPin, OUTPUT);
pinMode(knobPin, INPUT);

digitalWrite(grnPin, HIGH); // do a little "hello there" intro
delay(100);
digitalWrite(grnPin, LOW);
}

void loop()
{
digitalWrite(redPin, HIGH); // say we're doing something

pos = analogRead( knobPin ); // ranges from 0-1024

analogWrite( bluPin, pos/4 );

pulseWidth = pos + 1000; // convert to microseconds pulsewidth

digitalWrite(servoPin, HIGH); // make servo pulse
delayMicroseconds(pulseWidth);
digitalWrite(servoPin, LOW);

digitalWrite(redPin, LOW); // say we're done

delay(20);


}

Change log

r96 by tod.kurt on Mar 20, 2011   Diff
blinkmuino: fixed analogRead(), added
BlinkMServoKnob sketch
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1204 bytes, 56 lines
Powered by Google Project Hosting