// Adafruit PWM servo board GPIOtest
// https://wokwi.com/projects/412403579090783233
// Wokwi Custom Chip PSC9685
// from https://github.com/bonnyr/wokwi-pca9685-custom-chip
// with Adafruit PWM servo library from
// https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/blob/master/examples/gpiotest/gpiotest.ino
//
// See also:
// GPIO test https://wokwi.com/projects/412403579090783233
// Oscillator Test https://wokwi.com/projects/412405035088333825
// PWMtest https://wokwi.com/projects/412407132298758145
// Servotest https://wokwi.com/projects/412407755163620353
//
// For https://wokwi.com/projects/412407755163620353
//
// Uses https://github.com/bonnyr/wokwi-pca9685-custom-chip
// https://www.adafruit.com/product/815
// https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf
// Addresses 0x40+{A0:A5} -(avoid AllCall: 0xE0 & Reset 0x06)
//
// Custom chips playground
// See https://link.wokwi.com/custom-chips-alpha for more info
//
// For https://wokwi.com/projects/412407755163620353
//
// ======================= Copied Definitions ====================
// Copied some adafruit servo driver code rather than import the library - will do that later
// This explains the defines below etc...
/***************************************************
This is an example for our Adafruit 16-channel PWM & Servo driver
GPIO test - this will set a pin high/low
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/815
These drivers use I2C to communicate, 2 pins are required to
interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x5F);
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);
void setup() {
Serial.begin(9600);
Serial.println("GPIO test!");
pwm.begin();
pwm.setPWMFreq(1000); // Set to whatever you like, we don't use it in this demo!
// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
// some i2c devices dont like this so much so if you're sharing the bus, watch
// out for this!
Wire.setClock(400000);
}
void loop() {
// Drive each pin in a 'wave'
for (uint8_t pin=0; pin<4; pin++) { // DaveX was pin<16
pwm.setPWM(pin, 4096, 0); // turns pin fully on
delay(100);
pwm.setPWM(pin, 0, 4096); // turns pin fully off
}
}