6 position switch for Arducopter Ardupilot

You are addict of Hardware / Electronics / Tuning modifications on your 9XR, this place is for you !

6 position switch for Arducopter Ardupilot

Postby remick » 04 Feb 2014, 05:14

Hi,

I decide to replace one of the variable resistor with 6-way switch to have better Arducopter compatibility.

I bought switch here: click

Switch is double (2x 6-way) so "other" half I use to show switch position on 7-segment LED.
From the drawer I took attiny26, some resistors and of course 7-segment LED.

Here it is:

Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image


Source code for attiny26:
Code: Select all
//   Clock      = Internal Oscillator 1 MHz
//   High Fuse   = 0xF7
//   Low Fuse   = 0xE1
//     PORTA - display: PA0 - 7segA, PA1 - 7segB ...
//     PORTB - switch: PB0 - PB5

#include <avr/io.h>

unsigned char digits[10]=
{
   0b11000000,   // '0'
   0b11111001,   // '1'
   0b10100100,   // '2'
   0b10110000,   // '3'
   0b10011001,   // '4'
   0b10010010,   // '5'
   0b10000010,   // '6'
   0b11111000,   // '7'
   0b10000000,   // '8'
   0b10010000,   // '9'
};


void init_io(void);
void check_switch_pos(void);


int main(void)
{
   init_io();
   

   while(1)
   {

     check_switch_pos();

   }
}


void init_io(void)
{
   
   //initialize output pins
   DDRA = 0xFF;

   //turn all displays OFF
   PORTA = 0xFF;
   
   //initialize input pins
   DDRB = 0x00;

   //enable pull-up resistors
   PORTB = 0xFF;

}

void check_switch_pos(void){

   // read port value
   // display digit

   if (bit_is_clear(PINB, PB0))
        {
                PORTA = digits[1];
        }

    if (bit_is_clear(PINB, PB1))
        {
                PORTA = digits[2];
        }

   if (bit_is_clear(PINB, PB2))
        {
                PORTA = digits[3];
        }

   if (bit_is_clear(PINB, PB3))
        {
                PORTA = digits[4];
        }

   if (bit_is_clear(PINB, PB4))
        {
                PORTA = digits[5];
        }

   if (bit_is_clear(PINB, PB5))
        {
                PORTA = digits[6];
        }

}

remick
 
Posts: 1
Joined: 04 Feb 2014, 04:58

Re: 6 position switch for Arducopter Ardupilot

Postby dormantamas » 25 Apr 2015, 15:12

I'd like to replicate this mod. I have the same MCU, a usbASP programmer, and all the necessary resistors, the 7 segment display, components. I need help programming the MCU. Arduino IDE doesn't rcognise it with the default settings. I can't find the proper core files for it. I cant't compile the code, since it gives me error messages all the time. By the way: Is your 7 segment common anode, or common cathode? A simple circuit diagram would be nice, to know the exact parts used.
dormantamas
 
Posts: 1
Joined: 25 Apr 2015, 14:58


Return to 9XR Mods

Who is online

Users browsing this forum: No registered users and 0 guests