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.
main.cpp
- Committer:
- tyleralt
- Date:
- 2015-04-21
- Revision:
- 1:533b878c22ab
- Parent:
- 0:c8b0c4f50d18
- Child:
- 2:e2502545f2f0
File content as of revision 1:533b878c22ab:
#include "mbed.h"
#include <vector>
#define BUFFER_SIZE 16
#define NUMBER_OF_SLICES 120
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
class Point {
int positionRadian, positionHeight, positionDistance;
public:
Point (int , int , int );
int getArraySlice(void);
char getIdentifyingChar(void);
int getPositionDistance(void);
void moveUp();
void moveDown();
void rotateRight();
void rotateLeft();
void moveIn();
void moveOut();
};
Point :: Point (int posRadian, int posHeight, int posDistance){
positionRadian = posRadian;
positionHeight = posHeight;
positionDistance = posDistance;
}
int Point :: getArraySlice (void){
return positionRadian + offAngles[positionHeight];
}
char Point :: getIdentifyingChar(void){
return 0x01 << positionHeight;
}
int Point :: getPositionDistance(void){
return positionDistance;
}
void Point :: moveUp(){
if (positionHeight < 7){
positionHeight ++;
}
}
void Point :: moveDown(){
if(positionHeight > 0){
positionHeight --;
}
}
void Point :: rotateRight(){
positionRadian = (positionRadian + 1) % 120;
}
void Point :: rotateLeft(){
positionRadian = (positionRadian + 1) % 120;
}
void Point :: moveIn(){
if (positionDistance < 0){
positionDistance --;
}
}
void Point :: moveOut(){
if (positionDistance > 15){
positionDistance ++;
}
}
enum DrawingMode { line, point, circle };
DrawingMode currentMode;
Point pointer(60, 3, 8);
InterruptIn buttonMode(p15);
InterruptIn buttonUp(p16);
InterruptIn buttonDown(p17);
InterruptIn buttonRotateRight(p18);
InterruptIn buttonRotateLeft(p19);
InterruptIn buttonMoveOut(p20);
InterruptIn buttonMoveIn(p21);
InterruptIn buttonSelect(p22);
Ticker pointerBlinkTicker;
void sendPointOver (int slice, int distance, char height){
///TODO implement communications
}
void drawPoint(){
int pointerSlice = pointer.getArraySlice();
int pointerDistance = pointer.getPositionDistance();
char height = pointer.getIdentifyingChar();
sendPointOver(pointerSlice, pointerDistance, height);
}
void changeMode(){
if (currentMode == point){
currentMode = line;
}
if (currentMode == line){
currentMode = circle;
}
if (currentMode == circle){
currentMode = point;
}
}
void moveUp(){
if (currentMode == line){
drawPoint();
}
pointer.moveUp();
}
void moveDown(){
if (currentMode == line){
drawPoint();
}
pointer.moveDown();
}
void rotateRight(){
if (currentMode == line){
pointer.rotateRight();
}
pointer.rotateRight();
}
void rotateLeft(){
if (currentMode == line){
drawPoint();
}
pointer.rotateLeft();
}
void moveOut(){
if (currentMode == line){
drawPoint();
}
pointer.moveOut();
}
void moveIn(){
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);
}
void drawWholeCircle(){
int distance = pointer.getPositionDistance();
char height = pointer.getIdentifyingChar();
for (int i = 0; i < 120; i ++){
sendPointOver(i, distance, height);
}
}
void select(){
if (currentMode == point){
drawPoint();
}
if (currentMode == circle){
drawWholeCircle();
}
}
int main() {
currentMode = point;
buttonMode.rise(&changeMode);
buttonUp.rise(&moveUp);
buttonDown.rise(&moveDown);
buttonRotateRight.rise(&rotateRight);
buttonRotateLeft.rise(&rotateLeft);
buttonMoveOut.rise(&moveOut);
buttonMoveIn.rise(&moveIn);
buttonSelect.rise(&select);
pointerBlinkTicker.attach(&pointerBlink, 1);
for (int i = 0; i < NUMBER_OF_SLICES; i ++){
for (int j = 0; j < 16; j ++){
slice_data[i][j] = 0x00;
}
}
}