First init.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("seesaw started");
|
||||
|
||||
//set the PWM freq for all the servo pins
|
||||
crickit.setPWMFreq(CRICKIT_SERVO1, 50);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
//set some PWMS
|
||||
crickit.analogWrite(CRICKIT_SERVO1, 10000);
|
||||
crickit.analogWrite(CRICKIT_SERVO2, 5000);
|
||||
crickit.analogWrite(CRICKIT_SERVO3, 20000);
|
||||
crickit.analogWrite(CRICKIT_SERVO4, 45000);
|
||||
|
||||
// read an ADC
|
||||
Serial.print(crickit.analogRead(CRICKIT_SIGNAL4));
|
||||
Serial.print(",");
|
||||
|
||||
// read a captouch
|
||||
Serial.println(crickit.touchRead(CRICKIT_TOUCH2));
|
||||
|
||||
delay(1);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Adafruit Crickit Capacitive Touch Demo for Arduino
|
||||
//
|
||||
// Displays the value of Adafruit Crickit touchpad values when touched
|
||||
//
|
||||
// Tested with the Crickit + micro:bit, all good
|
||||
|
||||
#include "Adafruit_Crickit.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
#define CRICKIT_NUM_TOUCH 4
|
||||
#define CAPTOUCH_THRESH 500
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Set up serial monitor - be sure it is set to 9600
|
||||
Serial.println("Cap Touch Demo");
|
||||
if(!crickit.begin()) { // Check if Crickit is attached
|
||||
Serial.println("ERROR Starting crickit"); // If an error, print and
|
||||
while(1) ; // go to a infinite loop to stop
|
||||
}
|
||||
else Serial.println("seesaw started"); // success, we have a Crickit
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
for(int i=0; i<CRICKIT_NUM_TOUCH; i++){ // check each touch input
|
||||
uint16_t val = crickit.touchRead(i); // read the touch input
|
||||
|
||||
if(val > CAPTOUCH_THRESH){ // if the value read is > the threshold
|
||||
Serial.print("CT"); // print info to serial monitor
|
||||
Serial.print(i + 1);
|
||||
Serial.print(" touched! value: ");
|
||||
Serial.println(val);
|
||||
}
|
||||
}
|
||||
delay(100); // wait tiny bit between checks
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
#define NUM_DRIVES 4
|
||||
int drives[] = {CRICKIT_DRIVE1, CRICKIT_DRIVE2, CRICKIT_DRIVE3, CRICKIT_DRIVE4};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("4 Drive demo!");
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
//our default frequency is 1khz
|
||||
for(int i=0; i<NUM_DRIVES; i++)
|
||||
crickit.setPWMFreq(drives[i], 1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for(int i=0; i<NUM_DRIVES; i++){
|
||||
//turn all the way on
|
||||
crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_OFF);
|
||||
delay(100);
|
||||
|
||||
//turn all the way off
|
||||
crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_MAX);
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("1 Drive demo!");
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
//our default frequency is 1khz
|
||||
crickit.setPWMFreq(CRICKIT_DRIVE1, 1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//turn all the way on
|
||||
crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_OFF);
|
||||
delay(500);
|
||||
|
||||
//turn all the way off
|
||||
crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_MAX);
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
#include "seesaw_neopixel.h"
|
||||
#include "seesaw_servo.h"
|
||||
#define NEOPIX_PIN 20
|
||||
|
||||
#define USE_NEOPIX
|
||||
|
||||
seesaw_NeoPixel strip = seesaw_NeoPixel(24, NEOPIX_PIN, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_Crickit crickit;
|
||||
seesaw_Servo s1(&crickit);
|
||||
seesaw_Servo s2(&crickit);
|
||||
seesaw_Servo s3(&crickit);
|
||||
seesaw_Servo s4(&crickit);
|
||||
|
||||
#define NUM_SERVOS 4
|
||||
seesaw_Servo *servos[NUM_SERVOS] = {&s1, &s2, &s3, &s4};
|
||||
|
||||
#define COLOR_MAX 150
|
||||
#define RED strip.Color(COLOR_MAX, 0, 0)
|
||||
#define YELLOW strip.Color(COLOR_MAX, 150, 0)
|
||||
#define GREEN strip.Color(0, COLOR_MAX, 0)
|
||||
#define CYAN strip.Color(0, COLOR_MAX, 255)
|
||||
#define BLUE strip.Color(0, 0, COLOR_MAX)
|
||||
#define PURPLE strip.Color(180, 0, COLOR_MAX)
|
||||
|
||||
#define CRICKIT_NUM_ADC 8
|
||||
static const uint8_t crickit_adc[CRICKIT_NUM_ADC] = { CRICKIT_SIGNAL1, CRICKIT_SIGNAL2, CRICKIT_SIGNAL3, CRICKIT_SIGNAL4,
|
||||
CRICKIT_SIGNAL5, CRICKIT_SIGNAL6, CRICKIT_SIGNAL7, CRICKIT_SIGNAL8 };
|
||||
|
||||
#define CRICKIT_NUM_TOUCH 4
|
||||
static const uint8_t crickit_drive[CRICKIT_NUM_TOUCH] = {CRICKIT_DRIVE1, CRICKIT_DRIVE2, CRICKIT_DRIVE3, CRICKIT_DRIVE4};
|
||||
|
||||
#define CAPTOUCH_THRESH 500
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while(!Serial);
|
||||
if(!crickit.begin(0x49, A0)){
|
||||
Serial.println("ERROR Starting crickit");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("seesaw started");
|
||||
|
||||
if(!strip.begin(0x49, A0)){
|
||||
Serial.println("ERROR Starting neopix");
|
||||
while(1) delay(1);
|
||||
}
|
||||
Serial.println("neopix started!");
|
||||
|
||||
s1.attach(CRICKIT_SERVO1);
|
||||
s2.attach(CRICKIT_SERVO2);
|
||||
s3.attach(CRICKIT_SERVO3);
|
||||
s4.attach(CRICKIT_SERVO4);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
#ifdef USE_NEOPIX
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++)
|
||||
strip.setPixelColor(i, RED);
|
||||
strip.show();
|
||||
#endif
|
||||
|
||||
for(int i=0; i<CRICKIT_NUM_ADC; i++){
|
||||
Serial.print(crickit.analogRead(crickit_adc[i]));
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
//TODO: fix drive3 and drive4
|
||||
for(int i=0; i<4; i++){
|
||||
uint16_t val = crickit.touchRead(i);
|
||||
|
||||
if(val > CAPTOUCH_THRESH){
|
||||
crickit.analogWrite(crickit_drive[i], (1UL << 16) - 1);
|
||||
Serial.print("CT");
|
||||
Serial.print(i + 1);
|
||||
Serial.print(" touched! value: ");
|
||||
Serial.println(val);
|
||||
}
|
||||
else
|
||||
crickit.analogWrite(crickit_drive[i], 0);
|
||||
}
|
||||
|
||||
#ifdef USE_NEOPIX
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++)
|
||||
strip.setPixelColor(i, GREEN);
|
||||
strip.show();
|
||||
#endif
|
||||
|
||||
for(int i=0; i<NUM_SERVOS; i++){
|
||||
seesaw_Servo *s = servos[i];
|
||||
s->write(1000);
|
||||
}
|
||||
delay(500);
|
||||
|
||||
#ifdef USE_NEOPIX
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++)
|
||||
strip.setPixelColor(i, BLUE);
|
||||
strip.show();
|
||||
#endif
|
||||
|
||||
for(int i=0; i<NUM_SERVOS; i++){
|
||||
seesaw_Servo *s = servos[i];
|
||||
s->write(2000);
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
#include "seesaw_motor.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
seesaw_Motor motor_a(&crickit);
|
||||
seesaw_Motor motor_b(&crickit);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Dual motor demo!");
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
//attach motor a
|
||||
motor_a.attach(CRICKIT_MOTOR_A1, CRICKIT_MOTOR_A2);
|
||||
|
||||
//attach motor b
|
||||
motor_b.attach(CRICKIT_MOTOR_B1, CRICKIT_MOTOR_B2);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
motor_a.throttle(1);
|
||||
motor_b.throttle(-1);
|
||||
delay(1000);
|
||||
|
||||
motor_a.throttle(.5);
|
||||
motor_b.throttle(-.5);
|
||||
delay(1000);
|
||||
|
||||
motor_a.throttle(0);
|
||||
motor_b.throttle(0);
|
||||
delay(1000);
|
||||
|
||||
motor_a.throttle(-.5);
|
||||
motor_b.throttle(.5);
|
||||
delay(1000);
|
||||
|
||||
motor_a.throttle(-1);
|
||||
motor_b.throttle(1);
|
||||
delay(1000);
|
||||
|
||||
motor_a.throttle(0);
|
||||
motor_b.throttle(0);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
#include "seesaw_servo.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
#define NUM_SERVOS 4
|
||||
|
||||
//create an array of 4 servos with our crickit object
|
||||
seesaw_Servo servos[] = { seesaw_Servo(&crickit),
|
||||
seesaw_Servo(&crickit),
|
||||
seesaw_Servo(&crickit),
|
||||
seesaw_Servo(&crickit) };
|
||||
|
||||
//these are the pins they will be attached to
|
||||
int servoPins[] = { CRICKIT_SERVO1, CRICKIT_SERVO2, CRICKIT_SERVO3, CRICKIT_SERVO4 };
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
//begin the crickit
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
//attach the servos to their pins
|
||||
for(int i=0; i<NUM_SERVOS; i++)
|
||||
servos[i].attach(servoPins[i]); // attaches the servo to the pin
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//repeat for all 4 servos
|
||||
for(int i=0; i<NUM_SERVOS; i++){
|
||||
servos[i].write(0);
|
||||
delay(1000);
|
||||
servos[i].write(90);
|
||||
delay(1000);
|
||||
servos[i].write(180);
|
||||
delay(1000);
|
||||
servos[i].write(90);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
#include "seesaw_servo.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
seesaw_Servo myservo(&crickit); // create servo object to control a servo
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
myservo.attach(CRICKIT_SERVO1); // attaches the servo to CRICKIT_SERVO1 pin
|
||||
}
|
||||
|
||||
void loop() {
|
||||
myservo.write(0);
|
||||
delay(1000);
|
||||
myservo.write(90);
|
||||
delay(1000);
|
||||
myservo.write(180);
|
||||
delay(1000);
|
||||
myservo.write(90);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "Adafruit_Crickit.h"
|
||||
|
||||
Adafruit_Crickit crickit;
|
||||
|
||||
#define BUTTON_1 CRICKIT_SIGNAL1
|
||||
#define BUTTON_2 CRICKIT_SIGNAL2
|
||||
#define LED_1 CRICKIT_SIGNAL3
|
||||
#define LED_2 CRICKIT_SIGNAL4
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
if(!crickit.begin()){
|
||||
Serial.println("ERROR!");
|
||||
while(1) delay(1);
|
||||
}
|
||||
else Serial.println("Crickit started");
|
||||
|
||||
//Two buttons are pullups, connect to ground to activate
|
||||
crickit.pinMode(BUTTON_1, INPUT_PULLUP);
|
||||
crickit.pinMode(BUTTON_2, INPUT_PULLUP);
|
||||
|
||||
// Two LEDs are outputs, on by default
|
||||
crickit.pinMode(LED_1, OUTPUT);
|
||||
crickit.pinMode(LED_2, OUTPUT);
|
||||
crickit.digitalWrite(LED_1, HIGH);
|
||||
crickit.digitalWrite(LED_2, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if(!crickit.digitalRead(BUTTON_1))
|
||||
crickit.digitalWrite(LED_1, HIGH);
|
||||
else
|
||||
crickit.digitalWrite(LED_1, LOW);
|
||||
|
||||
if(!crickit.digitalRead(BUTTON_2))
|
||||
crickit.digitalWrite(LED_2, HIGH);
|
||||
else
|
||||
crickit.digitalWrite(LED_2, LOW);
|
||||
}
|
||||
Reference in New Issue
Block a user