Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 3:9e8eb12f831f
- Parent:
- 2:e2502545f2f0
- Child:
- 4:a7442c1faed1
--- a/main.cpp Wed Apr 22 00:28:29 2015 +0000
+++ b/main.cpp Fri Apr 24 07:09:48 2015 +0000
@@ -5,8 +5,7 @@
#include "MRF24J40.h"
-int offAngles [8] = {0, 180, 90, 270, 45, 225, 135, 315};
-char slice_data [NUMBER_OF_SLICES][16]; //[slice][specific led distance] (0 is closest) & with approppriate bit for each arm
+int offAngles [8] = {0, 180, 45, 225, 90, 270, 135, 315};
//*********************point class************************//
class Point {
@@ -30,7 +29,7 @@
positionDistance = posDistance;
}
int Point :: getArraySlice (void){
- return positionRadian + offAngles[positionHeight];
+ return (positionRadian + (offAngles[positionHeight]/3))%120;
}
char Point :: getIdentifyingChar(void){
return 0x01 << positionHeight;
@@ -52,15 +51,15 @@
positionRadian = (positionRadian + 1) % 120;
}
void Point :: rotateLeft(){
- positionRadian = (positionRadian + 1) % 120;
+ positionRadian = (positionRadian - 1) % 120;
}
void Point :: moveIn(){
- if (positionDistance < 0){
+ if (positionDistance > 0){
positionDistance --;
}
}
void Point :: moveOut(){
- if (positionDistance > 15){
+ if (positionDistance < 15){
positionDistance ++;
}
}
@@ -72,135 +71,224 @@
Point pointer(60, 3, 8);
+DigitalIn digitalMode(p15);
+DigitalIn digitalUp(p16);
+DigitalIn digitalDown(p17);
+DigitalIn digitalRotateRight(p18);
+DigitalIn digitalRotateLeft(p21);
+DigitalIn digitalMoveOut(p22);
+DigitalIn digtialMoveIn(p23);
+DigitalIn digitalSelect(p24);
+
InterruptIn buttonMode(p15);
InterruptIn buttonUp(p16);
InterruptIn buttonDown(p17);
InterruptIn buttonRotateRight(p18);
-InterruptIn buttonRotateLeft(p19);
-InterruptIn buttonMoveOut(p20);
-InterruptIn buttonMoveIn(p21);
-InterruptIn buttonSelect(p22);
-DigitalIn digitalMode(p15);
-DigitalIn digitalUp(p16);
-DigitalIn digitalDown(p17);
-DigitalIn digitalRotateRight(p18);
-DigitalIn digitalRotateLeft(p19);
-DigitalIn digotalMoveOut(p20);
-DigitalIn digtialMoveIn(p21);
-DigitalIn digitalSelect(p22);
+InterruptIn buttonRotateLeft(p21);
+InterruptIn buttonMoveOut(p22);
+InterruptIn buttonMoveIn(p23);
+InterruptIn buttonSelect(p24);
+
+bool registerButtons = true;
+Timeout buttonRegisterTimeout;
+Timeout unBlink;
Ticker pointerBlinkTicker;
MRF24J40 mrf(p11, p12, p13, p14, p26);
char txBuffer[128];
-char rxBuffer[128];
int rxLen;
+
void rf_send(char *data, uint8_t len)
{
//We need to prepend the message with a valid ZigBee header
uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len+8) );
-
+
for(uint8_t i = 0; i < len+8; i++) {
//prepend the 8-byte header
send_buf[i] = (i<8) ? header[i] : data[i-8];
}
//pc.printf("Sent: %s\r\n", send_buf+8);
-
+
mrf.Send(send_buf, len+8);
free(send_buf);
}
-void sendPointOver (int slice, int distance, char height){
+void sendPointOver (int slice, int distance, char height, char operation){
///TODO implement communications
- char sliceChar = (char) slice;
- char distanceChar = (char) distance;
- String data = sliceChar + distanceChar + height;
-
- strcpy(txBuffer, data);
- //Send the buffer
- rf_send(txBuffer, strlen(txBuffer) + 1);
- pc.printf("Sent: %s\r\n", txBuffer);
+ printf(" slice %i distance %i height %X operation %c \r\n", (char) slice, (char) distance, height, operation);
+ txBuffer [0] = (char) slice;
+ txBuffer [1] = (char)distance;
+ txBuffer [2] = height;
+ txBuffer [3] = operation;
+
+ rf_send(txBuffer, 5);
}
void drawPoint(){
+
int pointerSlice = pointer.getArraySlice();
int pointerDistance = pointer.getPositionDistance();
char height = pointer.getIdentifyingChar();
- sendPointOver(pointerSlice, pointerDistance, height);
+ sendPointOver(pointerSlice, pointerDistance, height, 'o');
}
-
+void registerButtonsAgain (){
+ registerButtons = true;
+}
//***************** all of the button reactions *********//
void changeMode(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("changeMode\r\n");
if (currentMode == point){
currentMode = line;
+ printf("line mode\r\n");
+ return;
}
if (currentMode == line){
currentMode = circle;
+ printf("circle mode\r\n");
+ return;
}
if (currentMode == circle){
currentMode = point;
+ printf("point mode\r\n");
+ return;
}
}
void moveUp(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("moveUp\r\n");
if (currentMode == line){
drawPoint();
}
pointer.moveUp();
}
void moveDown(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("moveDown\r\n");
if (currentMode == line){
drawPoint();
}
pointer.moveDown();
}
void rotateRight(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("rotaeRight\r\n");
if (currentMode == line){
+ drawPoint();
pointer.rotateRight();
+ wait(.3);
+ while (digitalRotateRight){
+ drawPoint();
+ pointer.rotateRight();
+ wait(.03);
+ }
+ return;
}
pointer.rotateRight();
+ wait(.3);
+ while (digitalRotateRight){
+ pointer.rotateRight();
+ wait(.03);
+ }
}
void rotateLeft(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("rotateLeft\r\n");
if (currentMode == line){
drawPoint();
+ pointer.rotateRight();
+ wait(.3);
+ while (digitalRotateLeft){
+ drawPoint();
+ pointer.rotateRight();
+ wait(.03);
+ }
+ return;
}
pointer.rotateLeft();
wait(.3);
- while(buttonRotateLeft.
+ while(digitalRotateLeft){
+ pointer.rotateLeft();
+ wait(.03);
+
+ }
+
}
void moveOut(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("moveOut\r\n");
if (currentMode == line){
drawPoint();
}
pointer.moveOut();
}
void moveIn(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf("moveIn\r\n");
if (currentMode == line){
drawPoint();
}
pointer.moveIn();
}
+
void pointerBlink(){
Point currentBlink = pointer;
int slice = currentBlink.getArraySlice();
int distance = currentBlink.getPositionDistance();
char height = pointer.getIdentifyingChar();
- sendPointOver(slice, distance, height);
- wait(.3);
- sendPointOver(slice, distance, height);
+ sendPointOver(slice, distance, height, 'x');
+ wait(1.5);
+ sendPointOver(slice, distance, height, 'x');
}
void drawWholeCircle(){
int distance = pointer.getPositionDistance();
char height = pointer.getIdentifyingChar();
for (int i = 0; i < 120; i ++){
- sendPointOver(i, distance, height);
+ sendPointOver(i, distance, height, 'o');
}
}
+
void select(){
+ if (!registerButtons){
+ return;
+ }
+ registerButtons = false;
+ buttonRegisterTimeout.attach(®isterButtonsAgain, .1);
+ printf(" select \r\n");
if (currentMode == point){
drawPoint();
}
@@ -208,10 +296,19 @@
drawWholeCircle();
}
}
-//***************** all of the button reactions finish*********//
+//****************end buttons section ************//
+
int main() {
+ printf(" started the program\r\n ");
+
+ uint8_t channel = 2;
+
+
+ //Set the Channel. 0 is default, 15 is max
+ mrf.SetChannel(channel);
+
currentMode = point;
buttonMode.rise(&changeMode);
buttonUp.rise(&moveUp);
@@ -221,14 +318,10 @@
buttonMoveOut.rise(&moveOut);
buttonMoveIn.rise(&moveIn);
buttonSelect.rise(&select);
- pointerBlinkTicker.attach(&pointerBlink, 1);
+ pointerBlinkTicker.attach(&pointerBlink, 1.0);
- for (int i = 0; i < NUMBER_OF_SLICES; i ++){
- for (int j = 0; j < 16; j ++){
- slice_data[i][j] = 0x00;
- }
- }
+ while(1);
}