having trouble converting from nano to the every for an ironman helmet
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 450
#define SERVO_FREQ 50
int buttonPin = 2; // Button pin
int ledPin = 6; // LED pin
int buttonState = HIGH;
int lastButtonState = HIGH; // Previous state of the button
unsigned long lastDebounceTime = 0; // Button debounce time
unsigned long debounceDelay = 50; // Delay for debouncing
int globalPos = 1; // 1 = Closed, 0 = Open
uint8_t records[7] = {0, 1}; // Indices for "open" (0) and "close" (1)
uint8_t buf[64]; // Buffer for recognized commands
void setup() {
Serial.begin(9600);
Serial.println("starting system");
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pwm.sleep(); // The controller is suspended at startup.
digitalWrite(ledPin, HIGH); // Make sure the LEDs are on at the beginning (helmet closed).
// Initial configuration of the servos to prevent erratic movements.
pwm.setPWM(0, 0, getAngleToPulse(750)); // Initial position Servo 0
pwm.setPWM(1, 0, getAngleToPulse(750)); // Initial position Servo 1
}
int getAngleToPulse(int angle) {
return map(angle, 0, 180, SERVOMIN, SERVOMAX);
}
void openHelmet() {
Serial.println("Opening the helmet...");
pwm.wakeup();
digitalWrite(ledPin, LOW); // Turn off the LEDs when opening.
// Cheek movement
for (uint16_t pulselen = 90; pulselen >= 20; pulselen--) {
pwm.setPWM(9, 0, getAngleToPulse(90 + 20 - pulselen));
pwm.setPWM(8, 0, getAngleToPulse(pulselen));
}
// Movement of the sides of the nose
for (uint16_t pulselen = 86; pulselen >= 10; pulselen--) {
pwm.setPWM(6, 0, getAngleToPulse(86 + 10 - pulselen));
pwm.setPWM(7, 0, getAngleToPulse(pulselen));
}
// Movement of the central eyebrow
for (uint16_t pulselen = 120; pulselen >= 40; pulselen--) {
pwm.setPWM(4, 0, getAngleToPulse(pulselen));
}
// Movement of the lateral eyebrows
for (uint16_t pulselen = 30; pulselen <= 90; pulselen++) {
pwm.setPWM(2, 0, getAngleToPulse(pulselen));
pwm.setPWM(3, 0, getAngleToPulse(30 + 90 - pulselen));
}
// Movement of the center of the nose
for (uint16_t pulselen = 110; pulselen >= 1; pulselen--) {
pwm.setPWM(5, 0, getAngleToPulse(pulselen));
}
// Movement of the main engines
for (uint16_t microsec = 750; microsec < 1950; microsec += 5) {
pwm.writeMicroseconds(0, microsec); // Left engine (Servo 0)
pwm.writeMicroseconds(1, 1950 + 750 - microsec); // Right motor (Servo 1)
}
Serial.println("Open helmet.");
}
void closehelmet() {
Serial.println("Closing the helmet...");
pwm.wakeup();
digitalWrite(ledPin, HIGH); // Turn on the LEDs when closing.
// Movement of the main engines
for (uint16_t microsec = 1950; microsec > 750; microsec -= 5) {
pwm.writeMicroseconds(0, microsec); // Left engine (Servo 0)
pwm.writeMicroseconds(1, 1950 + 750 - microsec); // Right engine (Servo 1)
}
// Movement of the center of the nose
for (uint16_t pulselen = 1; pulselen <= 110; pulselen++) {
pwm.setPWM(5, 0, getAngleToPulse(pulselen));
}
// Movement of the lateral eyebrows
for (uint16_t pulselen = 90; pulselen >= 30; pulselen--) {
pwm.setPWM(2, 0, getAngleToPulse(pulselen));
pwm.setPWM(3, 0, getAngleToPulse(30 + 90 - pulselen));
}
// Movement of the central eyebrow
for (uint16_t pulselen = 40; pulselen <= 120; pulselen++) {
pwm.setPWM(4, 0, getAngleToPulse(pulselen));
}
// Movement of the sides of the nose
for (uint16_t pulselen = 10; pulselen <= 86; pulselen++) {
pwm.setPWM(6, 0, getAngleToPulse(86 + 10 - pulselen));
pwm.setPWM(7, 0, getAngleToPulse(pulselen));
}
// Cheek movement
for (uint16_t pulselen = 20; pulselen <= 90; pulselen++) {
pwm.setPWM(9, 0, getAngleToPulse(90 + 20 - pulselen));
pwm.setPWM(8, 0, getAngleToPulse(pulselen));
}
Serial.println("Closed helmet.");
}
void loop() {
// Debounce for the button
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW && globalPos == 1) { // Button to open
globalPos = 0;
} else if (reading == LOW && globalPos == 0) { // Button to close
globalPos = 1;
}
}
lastButtonState = reading;
}





