I'm building a Nerf Rival Plasmacaster and I've got the servo motors and a laser module working from a Wii Nunchuk interface (Joystick moves servo motors, button c activates laser).
However, when I try to use the flywheels, (button z), it won't work.
At first I thought it might be an issue with power, so I used a L298 board to try and drive it and while the lights came on the L298, nothing else happened.
The only other thing that might be causing a problem is that I'm using a Nano and it worked successfully on an Uno in the past.
Any help would be appreciated.
#include <Servo.h>
#include <Wire.h>
#include "Nunchuk.h"
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
int pos1 = 0; // variable to store the servo position
int pos2 = 0; // variable to store the servo position
int laserPin = 11;
int enA = 6;
int in1 = 7;
int in2 = 8;
void setup() {
Wire.begin();
nunchuk_init_power(); // A1 and A2 is power supply
nunchuk_init();
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
pinMode (laserPin, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop() {
if (nunchuk_read()) {
pos1 = map(nunchuk_joystickX(), -128, 128, 180, 0);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
// pos2 = constrain(nunchuk_accelY(),-150, 150);
//pos2 = map(pos2,-150, 150, 180, 100);
//myservo2.write(pos1); // tell servo to go to position in variable 'pos'
pos2 = map(nunchuk_joystickY(), -128, 128, 45, 170);
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
if (nunchuk_buttonC() == HIGH) {
// turn laser on:
digitalWrite (laserPin, HIGH);
} else {
// turn laser off:
digitalWrite(laserPin, LOW);
}
if (nunchuk_buttonZ() == HIGH) {
// turn flywheels on:
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
} else {
// turn flywheels off:
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);;
}
}
delay(20);
}