I have a transistor w/ motor on pin 10 on my arduino duilminove. I am trying to analogWrite() it. I loaded the fade example and it worked great. I added it to my code of my project and it does not work, only when it is set to 255 it goes. what can cause this? I have the servo library in use can this cause this?
here is my code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
int incomingByte = 0;
int r = 7;
int g = 6;
int b = 5;
int bulb = 9;
int vibe1 = 10;
void setup()
{
Serial.begin(9600);
myservo.attach(11);
//pinMode(10, OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(r, OUTPUT);
pinMode(g, OUTPUT);
pinMode(b, OUTPUT);
pinMode(bulb, OUTPUT);
analogWrite(10, 254);
}
void loop() {
// variables to read the pulse widths:
int pulseX, pulseY;
// variables to contain the resulting accelerations
int accelerationX, accelerationY;
// read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);
// convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's:
// earth's gravity is 1000 milli-g's, or 1g.
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;
int s = map(accelerationX,-1023,1023,1,1000);
Serial.write(s / 256);
Serial.write(s % 256);
s = map(accelerationY,-1023,1023,1,1000);
Serial.write(s / 256);
Serial.write(s % 256);
s = map(analogRead(A0),0,1023,1,1000);
Serial.write(s / 256);
Serial.write(s % 256);
s = map(analogRead(A1),0,1023,1000,1);
Serial.write(s / 256);
Serial.write(s % 256);
s = map(analogRead(A2),0,1023,1,254);
Serial.write(s);
if (Serial.available() > 0)
{
incomingByte = Serial.read();
if (incomingByte == 200)
{
digitalWrite(bulb, HIGH);
}
if (incomingByte == 201)
{
digitalWrite(bulb, LOW);
}
if (incomingByte == 202)
{
digitalWrite(b, HIGH);
}
if (incomingByte == 203)
{
digitalWrite(b, LOW);
}
if (incomingByte == 204)
{
digitalWrite(g, HIGH);
}
if (incomingByte == 205)
{
digitalWrite(g, LOW);
}
if (incomingByte == 206)
{
digitalWrite(r, HIGH);
}
if (incomingByte == 207)
{
digitalWrite(r, LOW);
}
if (incomingByte == 208) {analogWrite(10, 50);}
if (incomingByte == 209) {analogWrite(10, 90);}
if (incomingByte == 210) {analogWrite(10, 140);}
if (incomingByte == 211) {analogWrite(10, 190);}
if (incomingByte == 212) {analogWrite(10, 220);}
if (incomingByte == 213) {analogWrite(10, 255);}
if (incomingByte < 180)
{
myservo.write(incomingByte);
}
}
delay(1);
}