here is the entire code, some of the names may be on norwegian. the function I am looking for a function that makes the DC motor go faster as I hold the button on my controller down.
#include <Servo.h>
#include <IRremote.h>
Servo myservo;
int RECV_PIN = 7;
const int ledpin = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean LEDon = true; // initializing LEDon as true
boolean SERVOon = true;
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
void setup()
{
pinMode (ledpin, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
myservo.attach(6);
myservo.write(90); // set servo to mid-point
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
if (results.value == 16738455) // change zero to your IR remote button number
{
if (LEDon == true) // is LEDon equal to true?
{
LEDon = false;
digitalWrite(ledpin, HIGH);
delay(100); // keeps the transistion smooth
}
else
{
LEDon = true;
digitalWrite(ledpin, LOW);
delay(100);
}
}
// svinge til venstre
if (results.value == 16716015) {
if (SERVOon == true) // is LEDon equal to true?
{
SERVOon = false;
myservo.write(0);
delay(15);
}
else
{
SERVOon = true;
delay(15);
myservo.write(90);
}
}
// svinge til høyre
if (results.value == 16734885) {
if (SERVOon == true) // is LEDon equal to true?
{
SERVOon = false;
myservo.write(180);
delay(15);
}
else
{
SERVOon = true;
delay(15);
myservo.write(90);
}
}
//sving reset
if (results.value != 16734885 ||16716015){
myservo.write(90);
}
// for å gå frammover
if (results.value == 16718055) {
move(1, 255, 0); //motor 1, full speed, right
move(2, 255, 0); //motor 2, full speed, right
}
// for å gå bakover
if (results.value == 16730805) {
int fart = 0;
for (int motorValue = 0; motorValue >= 255;) {
if (results.value == 16730805) {
motorValue += 5;
fart = motorValue;
}
}
if (results.value == 16730805) {
move(1, fart, 1);
move(2, fart, 1);
}
}
// stop
if (results.value == 16726215) {
stop();
}
}
void move(int motor, int speed, int direction) {
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if (direction == 1) {
inPin1 = HIGH;
inPin2 = LOW;
}
if (motor == 1) {
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
} else {
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop() {
//enable standby
digitalWrite(STBY, LOW);
}